Software:Pygame

From HandWiki
Pygame
Original author(s)Lenard Lindstrom, René Dudfield, Pete Shinners, Nicholas Dudfield, Thomas Kluyver, and others[1]
Developer(s)Pygame Community
Initial release28 October 2000; 25 years ago (2000-10-28)[2][3]
Stable release
2.6.1 / 30 September 2024; 2 years ago (2024-09-30)[4]
Written inC, Python, Cython, and Assembly[5][6]
Operating systemCross-platform
TypeAPI
LicenseGNU Lesser General Public License

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.[7]

History

Pygame was originally written by Pete Shinners to replace PySDL after its development stalled.[8][9] It has been a community project since 2000[10] and is released under the free software GNU Lesser General Public License[11] (which "provides for Pygame to be distributed with open source and commercial software"[12]).

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.[13]

Pygame 2.0 released on 28 October 2020, Pygame's 20th anniversary.[14]

Features

Core Features

Pygame uses the Simple DirectMedia Layer (SDL) library,[lower-alpha 1] 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.[15]

A screenshot of a "hello world" application made in Pygame, featuring green text over a blue background, contained in a rectangular window.
A simple "hello world" application made in Pygame.

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.[16]

SDL also supports audio, which Pygame exposes via the Mixer module.[16]

Applications using Pygame can run on Android phones and tablets with the use of Pygame Subset for Android (pgs4a).[17] Sound, vibration, keyboard, and accelerometer are supported on Android.[18]

Pygame Community Edition

Following disagreements between former core developers and the repository owner, a fork known as pygame-ce (Community Edition) was created.[19]

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.[19][20]

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 incudes 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.[21]

Community

There is a regular competition, called PyWeek, to write games using Python (and usually but not necessarily, Pygame).[22][23][24] The community has created many tutorials for Pygame.[25][26][27][28][29]

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.[30][31]

Sample code

The following code makes an image of a raccoon ("raccoon.png") bounce when hitting an edge.

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()

Notable games using Pygame

See also

Notes

  1. ↑ Pygame 2 and later versions are based on SDL2, while earlier releases were based on SDL1.[34]

References

  1. ↑ "Contributors to Pygame". GitHub. https://github.com/pygame/pygame/graphs/contributors. 
  2. ↑ Shinners, Pete. "Python Pygame Introduction - History". http://www.pygame.org/docs/tut/PygameIntro.html. 
  3. ↑ "Downloads - Pygame - Python game development". https://pypi.python.org/pypi/Pygame/. 
  4. ↑ "PyGame 2.6.1 - Python 3.13 bugfix release". https://github.com/pygame/pygame/releases/tag/2.6.1. 
  5. ↑ "About Pygame". GitHub. https://www.pygame.org/wiki/about. 
  6. ↑ "GettingStarted". https://www.pygame.org/wiki/GettingStarted. 
  7. ↑ Alam, Imran (2023-07-02). "How to Implement a Dialogue System in Pygame" (in en). https://www.makeuseof.com/implement-dialogue-system-in-pygame/. 
  8. ↑ "Pygame Intro — pygame v2.0.0.dev3 documentation". http://www.pygame.org/docs/tut/PygameIntro.html. 
  9. ↑ "pySDL sourceforge page". https://sourceforge.net/projects/pysdl/. 
  10. ↑ "commit by other authors". GitHub. https://github.com/pygame/pygame/commit/a4e0f865c591980e7aa2a160a92a2c9098a678ec. 
  11. ↑ "About - pygame wiki". http://www.pygame.org/wiki/about. 
  12. ↑ "Pygame Front Page — pygame v2.0.1.dev1 documentation". https://www.pygame.org/docs/. 
  13. ↑ "pygame 1.9.5 released into the wilds". https://www.pygame.org/news/2019/3/1-9-5-released-into-the-wilds. 
  14. ↑ "pygame 2.0 - the happy dance birthday release". GitHub. https://github.com/pygame/pygame/releases/tag/2.0.0. 
  15. ↑ pygame. "Initial revision · pygame/pygame@a4e0f86" (in en). https://github.com/pygame/pygame/commit/a4e0f865c591980e7aa2a160a92a2c9098a678ec. 
  16. ↑ 16.0 16.1 "Pygame docs". https://www.pygame.org/docs/. 
  17. ↑ "Example of using RAPT to package pygame(_sdl2) games.: renpytom/rapt-pygame-example". GitHub. 1 April 2019. https://github.com/renpytom/rapt-pygame-example. 
  18. ↑ "API — Pygame Subset for Android". http://pygame.renpy.org/api.html. 
  19. ↑ 19.0 19.1 "pygame - Community Edition". https://pypi.org/project/pygame-ce/. 
  20. ↑ pygame-community. "Release 2.1.3 · pygame-community/pygame-ce" (in en). https://github.com/pygame-community/pygame-ce/releases/tag/2.1.3. 
  21. ↑ pygame-community. "Releases · pygame-community/pygame-ce" (in en). https://github.com/pygame-community/pygame-ce/releases. 
  22. ↑ "PyWeek - Python Game Programming Challenge". http://www.pyweek.org/. 
  23. ↑ Gee, Sue (29 March 2013). "Why PyWeek: An Interview with Richard Jones". https://www.i-programmer.info/professional-programmer/i-programmer/5697-why-pyweek-an-interview-with-richard-jones-.html. 
  24. ↑ "PyWeek - Python Wiki". https://wiki.python.org/moin/PyWeek. 
  25. ↑ "pygame documentation: Tutorials". http://www.pygame.org/docs/. 
  26. ↑ Siddiqi (2020-06-27). "Python Game projects with source code" (in en-US). https://coderslegacy.com/python-game-projects-with-source-code/. 
  27. ↑ Shinners, Pete. "Line by line tutorial - Tutorial for beginners". http://pygame.org/docs/tut/chimp/ChimpLineByLine.html. 
  28. ↑ "Creating Games with Python - A tutorial explaining how to use pygame for game development and improved execution". http://www.linuxjournal.com/article/7694. 
  29. ↑ "Arinoid tutorials video tutorials at ShowMeDo". http://showmedo.com/videos/series?name=pythonArellanoPyGameSeries. 
  30. ↑ "Reddit". https://www.reddit.com/r/pygame/. 
  31. ↑ "Join the Pygame Community Discord Server!". https://discord.com/invite/pygame-community-772505616680878080. 
  32. ↑ "fretsonfire/src at master · skyostil/fretsonfire" (in en). https://github.com/skyostil/fretsonfire. 
  33. ↑ "Dangerous High School Girls in Trouble!". http://pygame.org/project-Dangerous+High+School+Girls+in+Trouble!-791-.html. 
  34. ↑ "pygame 1.9.5 released into the wilds". https://www.pygame.org/news/2019/3/1-9-5-released-into-the-wilds.