Pygame
Pygame (בעברית: פָּיְגֵיים) הוא סט של מודולים בשפת פייתון, שעוצבו לצורך קידוד משחקי וידאו, והוא פורסם לראשונה באוקטובר 2000. הוא מכיל ספריות של גרפיקה וסאונד שעוצבו כך שיתאימו לשימוש בשפת התכנות פייתון. Pygame הוא חוצה פלטפורמות, כלומר, ניתן להשתמש בו במספר מערכות הפעלה.
מפתח |
קהילת Pygame. יוצרים מקוריים: Lenard Lindstrom, René Dudfield, Pete Shinners, Nicholas Dudfield, Thomas Kluyver, and others[1] |
---|---|
מחזור חיים | 28 באוקטובר 2000 – הווה (23 שנים) |
גרסה אחרונה | 2.0.1 (24 בדצמבר 2020) |
מערכת הפעלה | חוצה פלטפורמות |
נכתבה בשפות | Assembly |
סוג רישיון | GNU Lesser General Public License |
קוד מקור | https://github.com/pygame/pygame/ |
קטגוריה | יצירת משחקי וידאו |
https://www.pygame.org/ | |
היסטוריה
עריכהPygame פותח במקור על ידי פיט שינרס (Pete Shinners) על מנת להחליף את ספריית PySDL[1] לאחר שפיתוחה התעכב. Pygame פותח על ידי הקהילה משנת 2000, ופורסם תחת הרישיון החופשי והחינמי LGPL.
ארכיטקטורה ופיצ'רים
עריכהPygame משתמש בספרית Simple DirectMedia Layer, (בקיצור SDL), על מנת להשיג תכנות משחקים בזמן אמת מבלי המכניקות ברמות הנמוכות יותר של שפות C ונגזרותיה. אפליקציות ב-Pygame יכולות לרוץ במערכת ההפעלה אנדרואיד באמצעות השימוש ב Pygame Subset For Android ( בקיצור: pgs4a ). שמע, רטט, מקלדת, וכו נתמכים באנדרואיד.
ספריות עזר ל-Pygame
עריכהPygame עצמו אינו מכיל תמיכה מובנית בגרפיקה מתקדמת יותר כגון כפתורים, תוויות, scroll bar, color picker וכו'. לשם כך, פותחו ספריות עזר אשר מספקות את הכלים הללו, ועוד. דוגמה למספר ספריות פופולריות לכך:
דוגמאות קוד
עריכהדוגמה לתוכנית Hello World פשוטה ב-Pygame[7]:
import pygame, sys
from pygame.locals import *
#Set up pygame
pygame.init()
#Set up the window
windowSurface = pygame.display.set_mode((500, 400), 0, 32)
pygame.display.set_caption('Hello World')
#Set up the colors
BLACK = (0,0,0)
RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0,0,255)
WHITE = (255,255,255)
#Set up fonts
basicFont = pygame.font.SysFont(None, 48)
#Set up the text
text = basicFont.render('HELLO WORLD', True, BLACK)
textRect = text.get_rect()
textRect.centerx = windowSurface.get_rect().centerx
textRect.centery = windowSurface.get_rect().centery
#Draw the white background onto the surface
windowSurface.fill(WHITE)
#Get a pixel array of the surface
pixArray = pygame.PixelArray(windowSurface)
pixArray[480][380] = BLACK
del pixArray
#Draw the text onto the surface
windowSurface.blit(text,textRect)
#Draw the window onto the screen
pygame.display.update()
#Run the game loop
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
משחקים שפותחו ב-Pygame
עריכהראו גם
עריכהקישורים חיצוניים
עריכה- אתר האינטרנט הרשמי של Pygame
הערות שוליים
עריכה- ^ pySDL2, https://pypi.org/
- ^ Documentation - Home Page
- ^ ThorPy
- ^ SGC 0.2.1, www.pygame.org
- ^ OcempGui, www.pygame.org
- ^ pygame-widgets 1.0.0
- ^ https://gist.github.com/nicolasfig, HelloPygame.py, github.com