pygame是跨平台Python模块组,专为电子游戏设计。包含图像、声音。建立在SDL基础上,允许实时电子游戏研发而无需被低階语言,如C语言或是更低階的組合語言束缚。基于这样一个设想,所有需要的游戏功能和理念都(主要是图像方面)完全简化位游戏逻辑本身,所有的资源结构都可以由高级语言提供,如Python。
pygame原为代替突然停止的pySDL。
pygame在Android
pygame應用程式能夠在Android手機和平板執行,採用pygame對於Android的子集(pgs4a)。 支援Android的聲音,振動,鍵盤和加速。但缺點是沒有辦法在iOS上執行pygame應用程式。其它pgs4a的主要限制是缺乏對於多點觸控的支援, 這使得雙指縮放,以及旋轉無法使用。另一個pygame在Android子集的替代方案是Kivy,它包含了多點觸控及iOS的支援。
例子
這段代碼假設在它運行的同一個目錄中有一個名為 ball.png 的(球的)圖像,它將在窗口中快速移動。
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 width:
speed[0] = -speed[0]
if ballrect.top height:
speed[1] = -speed[1]
screen.fill(black)
screen.blit(ball, ballrect)
pygame.display.flip()
其他
展示:
- Pyweek,游戏制作竞赛,时间限制在7天内
- Ludum Dare,LD48 游戏制作竞赛,时间限制在48小时内
2D引擎和库:
- [https://github.com/parogers/pgu Phil's Pygame Utilities (PGU)]是增强pygame的库和工具的集合。工具tile编辑器和一个关卡编辑器。(tile, isometric, hexagonal)GUI增强包括全功能GUI,html渲染,文档输出,文本渲染。函式庫包括精靈和拼接圖電子遊戲引擎(瓷磚圖, 立体圖, 六角圖), 和一個狀態引擎,计时器,高分系统。
- Pyglet,一个OpenGL库,类似pygame
社群
有定期的競賽,叫做PyWeek. 使用Python寫出遊戲(通常但不一定使用pygame)。社群已經創造了許多Pygame的教學。
参考
链接
- [https://web.archive.org/web/20130922091530/http://www.pygame.org/ Pygame homepage]—Pygame documentation, wiki, news, download and more.
- [https://web.archive.org/web/20081217081451/http://rene.f0o.com/mywiki/PythonGameProgramming An Introduction to Python Game Programming] - written by Rene Dudfield and Geoff Howland
- [http://www.pyweek.org Pyweek homepage]—regular contest to write a game during one week using Python (most entries use pygame).
- [news://gmane.comp.python.pygame Pygame newsgroup] [https://web.archive.org/web/20090311035559/http://news.gmane.org/gmane.comp.python.pygame (web access)]— the "official" Pygame newsgroup,requires registration
- [https://web.archive.org/web/20050205015600/http://www.pygame.org/docs/tut/chimp/ChimpLineByLine.html Line by line tutorial]—Tutorial for beginners by Pete Shinners.
- [http://www.linuxjournal.com/article/7694 Creating Games with Python] - A tutorial explaining how to use Pygame for game development and improved execution.
- [https://web.archive.org/web/20070429080319/http://showmedo.com/videos/series?name=pythonMayerPyGameSeries pyGame Basics] and [https://web.archive.org/web/20070429111639/http://showmedo.com/videos/series?name=pythonArellanoPyGameSeries Arinoid tutorials] video tutorials at showmedo
- [https://web.archive.org/web/20081212113920/http://www.apress.com/book/view/1590598725 Beginning Game Development with Python and Pygame] -- A new book discussing game development using Pygame
- [https://web.archive.org/web/20110906045624/http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470068221.html Game Programming the L Line] -- A book that introduces programming and game development with Python and pygame
- [http://pyopengl.sourceforge.net/ pyOpenGL] - Python OpenGL Bindings
评论 (0)