開發者 | pygame Community |
---|---|
首次發布 | 2000年10月表達式錯誤:無法識別詞語「no」。日[1][2] |
穩定版本 | 2.0.1 (2020年12月24日[3]) |
操作系統 | 跨平台 |
類型 | API |
許可協議 | GNU寬通用公共許可證 |
網站 | http://www.pygame.org |
pygame[4]是跨平台Python模塊,專為電子遊戲設計。包含圖像、聲音。建立在SDL基礎上,允許實時電子遊戲研發而無需被低階語言,如C語言或是更低階的組合語言束縛。基於這樣一個設想,所有需要的遊戲功能和理念都(主要是圖像方面)完全簡化位遊戲邏輯本身,所有的資源結構都可以由高級語言提供,如Python。
pygame原為代替突然停止的pySDL[5]。
pygame在Android
pygame應用程式能夠在Android手機和平板執行,採用pygame對於Andorid的子集(pgs4a)。[6]支援Android的聲音,振動,鍵盤和加速。[7]但缺點是沒有辦法在iOS上執行pygame應用程式。其它pgs4a的主要限制是缺乏對於多點觸控的支援, 這使得雙指縮放,以及旋轉無法使用。另一個pygame在Android子集的替代方案是Kivy,[8]它包含了多點觸控及iOS的支援。
例子
這段代碼假設在它運行的同一個目錄中有一個名為 ball.png 的(球的)圖像,它將在窗口中快速移動。[9]
import sys, pygame
pygame.init()
size = width, height = 320, 240
speed = [2, 2]
black = 0, 0, 0
screen = pygame.display.set_mode(size)
ball = pygame.image.load("ball.png")
ballrect = ball.get_rect()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1]
screen.fill(black)
screen.blit(ball, ballrect)
pygame.display.flip()
其他
展示:
- Pyweek,遊戲製作競賽,時間限制在7天內
- Ludum Dare,LD48 遊戲製作競賽,時間限制在48小時內
2D引擎和庫:
- Phil's Pygame Utilities (PGU)是增強pygame的庫和工具的集合。工具tile編輯器和一個關卡編輯器。(tile, isometric, hexagonal)GUI增強包括全功能GUI,html渲染,文檔輸出,文本渲染。函式庫包括精靈和拚接圖電子遊戲引擎(瓷磚圖, 立體圖, 六角圖), 和一個狀態引擎,計時器,高分系統。
- Pyglet,一個OpenGL庫,類似pygame
社群
有定期的競賽,叫做PyWeek. 使用Python寫出遊戲(通常但不一定使用pygame)。[10][11][12]社群已經創造了許多Pygame的教學。[13][14][15][16][17][18]
參考
- ↑ Shinners, Pete. Python Pygame Introduction - History. [2018-10-18].
- ↑ Downloads - Pygame - Python game development. [2018-10-18].
- ↑ pygame 2.0.1 - The Age Of Aquarius release. GitHub.
- ↑ About — wiki. [2019-12-30].
- ↑ Libregamewiki's article on Pygame. [2008-12-19].
- ↑ 存档副本. [2015-09-03].
- ↑ 存档副本. [2014-10-14].
- ↑ 存档副本. [2015-09-03].
- ↑ Zed Shaw. Learn Python the hard way. Addison-Wesley Professional. 2017. ISBN 978-0134692883.
- ↑ PyWeek - Python Game Programming Challenge. [2018-08-09].
- ↑ 存档副本. [2018-08-09].
- ↑ 存档副本. [2018-08-09].
- ↑ pygame documentation: Tutorials. [2017-11-12].
- ↑ Shinners, Pete. Line by line tutorial — Tutorial for beginners. [2008-12-19].
- ↑ Creating Games with Python - A tutorial explaining how to use Pygame for game development and improved execution. [2008-12-19].
- ↑ PyGame Tutorials - tutorials with OOP approach. [2018-08-09].
- ↑ pyGame Basics. ShowMeDo.com. [2008-12-19].
- ↑ Arinoid tutorials video tutorials at ShowMeDo. [2008-12-19].
鏈接
- Pygame homepage—Pygame documentation, wiki, news, download and more.
- An Introduction to Python Game Programming - written by Rene Dudfield and Geoff Howland
- Pyweek homepage—regular contest to write a game during one week using Python (most entries use pygame).
- Pygame newsgroup[永久失效連結] (web access)— the "official" Pygame newsgroup,requires registration
- Line by line tutorial—Tutorial for beginners by Pete Shinners.
- Creating Games with Python - A tutorial explaining how to use Pygame for game development and improved execution.
- pyGame Basics and Arinoid tutorials video tutorials at showmedo
- Beginning Game Development with Python and Pygame—A new book discussing game development using Pygame
- Game Programming the L Line—A book that introduces programming and game development with Python and pygame
- pyOpenGL - Python OpenGL Bindings