开发者 | 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