Pygame
Template:Short description Template:Use dmy dates Template:Infobox software Pygame is a cross-platform library of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language.[1]
History
Pygame was originally written by Pete Shinners to replace PySDL after its development stalled.[2][3] It has been a community project since 2000[4] and is released under the free software GNU Lesser General Public License[5] (which "provides for Pygame to be distributed with open source and commercial software"[6]).
Development of version 2
Pygame version 2 was planned as "Pygame Reloaded" in 2009, but development and maintenance of Pygame completely stopped until the end of 2016 with version 1.9.1. After the release of version 1.9.5 in March 2019, development of a new version 2 was active on the roadmap.[7]
Pygame 2.0 released on 28 October 2020, Pygame's 20th anniversary.[8]
Features
Core Features
Pygame uses the Simple DirectMedia Layer (SDL) library,Template:Efn with the intention of allowing real-time computer game development without the low-level mechanics of the C programming language and its derivatives. This is based on the assumption that the most expensive functions inside games can be abstracted from the game logic, making it possible to use a high-level programming language, such as Python, to structure the game.[9]
Other features that SDL does have include vector math, collision detection, 2D sprite scene graph management, MIDI support, camera, pixel-array manipulation, transformations, filtering, advanced freetype font support, and drawing.[10]
SDL also supports audio, which Pygame exposes via the Mixer module.[10]
Applications using Pygame can run on Android phones and tablets with the use of Pygame Subset for Android (pgs4a).[11] Sound, vibration, keyboard, and accelerometer are supported on Android.[12]
Pygame Community Edition
Following disagreements between former core developers and the repository owner, a fork known as pygame-ce (Community Edition) was created.[13]
This fork was originally created as a means to add several features that were, at the time, wanted but missing in the core release of Pygame. These features include support for Python 3.11, faster surface blitting, support for WebAssembly (WASM), and several smaller optimizations and feature additions. This fork also commenced a new, more democratic governing body for pygame-ce aimed at solving the approval slowdowns present in the core version.[13][14]
Since this initial release, the community edition has added several new features not present in the core version, including support for the latest versions of Python (all the way up to 3.15), and continued optimizations. Ongoing work includes migrating the community edition to run on SDL3, which as the team notes, primarily differs in interface from its predecessor, SDL2, in how it handles audio.[15]
Community
There is a regular competition, called PyWeek, to write games using Python (and usually but not necessarily, Pygame).[16][17][18] The community has created many tutorials for Pygame.[19][20][21][22][23]
Pygame also has a community-led subreddit on Reddit, where developers post their creations and ideas, and a Discord community server, where people discuss various aspects of the platform.[24][25]
Sample code
The following code makes an image of a raccoon ("raccoon.png") bounce when hitting an edge. <syntaxhighlight lang="python"> import pygame, sys
pygame.init() screen = pygame.display.set_mode((1280, 720)) clock = pygame.time.Clock() clock.tick(30) black = 0, 0, 0 raccoon = pygame.image.load("raccoon.png") raccoon = pygame.transform.scale(raccoon, (200, 140)) raccoonrect = raccoon.get_rect() velocity = [1, 1]
while True:
raccoonrect = raccoonrect.move(velocity)
if raccoonrect.left < 0 or raccoonrect.right > 1280:
velocity[0] = -velocity[0]
raccoon = pygame.transform.flip(raccoon, True, False)
if raccoonrect.top < 0 or raccoonrect.bottom > 720:
velocity[1] = -velocity[1]
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# screen update
screen.fill(black)
screen.blit(raccoon, raccoonrect)
pygame.display.flip()
</syntaxhighlight>
Notable games using Pygame
See also
Notes
References
External links
- Template:Official website
- Pygame newsgroup (web access) - the "official"
- Pygame Subset for Android (PGS4A)
- pyOpenGL - Python OpenGL Bindings
- Pygame-SDL2 - a reimplementation of Pygame APIs on top of SDL2
- PySDL2 - a wrapper around the SDL2 library similar to the discontinued PySDL project
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ 10.0 10.1 Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ 13.0 13.1 Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- ↑ Template:Cite web
- Pages with broken file links
- Application programming interfaces
- Free computer libraries
- Free software programmed in Python
- Graphics libraries
- Linux APIs
- MacOS APIs
- Python (programming language) libraries
- Simple DirectMedia Layer
- Video game development software
- Video game development software for Linux
- Windows APIs