Pygame: Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
imported>Leo72
top: yet another updated release
 
minor edit
 
Line 16: Line 16:
| latest release version = 2.6.1
| latest release version = 2.6.1
| latest release date = {{Start date and age|2024|09|30|df=y}}<ref>{{cite web |url= https://github.com/pygame/pygame/releases/tag/2.6.1|access-date=2025-03-16 |title=PyGame 2.6.1 - Python 3.13 bugfix release}}</ref>
| latest release date = {{Start date and age|2024|09|30|df=y}}<ref>{{cite web |url= https://github.com/pygame/pygame/releases/tag/2.6.1|access-date=2025-03-16 |title=PyGame 2.6.1 - Python 3.13 bugfix release}}</ref>
| programming language = [[Python (programming language)|Python]], [[C (programming language)|C]], [[Cython]], and [[Assembly language|Assembly]]<ref name="about">{{cite web|url=https://www.pygame.org/wiki/about|title=About Pygame|publisher=GitHub|access-date=31 August 2019|archive-url=https://web.archive.org/web/20190918143814/http://www.pygame.org/wiki/about|archive-date=18 September 2019|url-status=dead}}</ref><ref>{{cite web|url=https://www.pygame.org/wiki/GettingStarted|title=GettingStarted|website=Pygame.org}}</ref>
| programming language = [[C (programming language)|C]], [[Python (programming language)|Python]], [[Cython]], and [[Assembly language|Assembly]]<ref name="about">{{cite web|url=https://www.pygame.org/wiki/about|title=About Pygame|publisher=GitHub|access-date=31 August 2019|archive-url=https://web.archive.org/web/20190918143814/http://www.pygame.org/wiki/about|archive-date=18 September 2019|url-status=dead}}</ref><ref>{{cite web|url=https://www.pygame.org/wiki/GettingStarted|title=GettingStarted|website=Pygame.org}}</ref>
| operating system = [[Cross-platform]]
| operating system = [[Cross-platform]]
| platform =  
| platform =  
Line 30: Line 30:


==History==
==History==
Pygame was originally written by [[Pete Shinners]] to replace [[PySDL]] after its development stalled.<ref name="pygame-intro"/><ref>{{cite web |url=http://sourceforge.net/projects/pysdl/ |title=pySDL sourceforge page|website=Sourceforge.net}}</ref> It has been a [[free software community|community]] project since 2000<ref>{{cite web|url=https://github.com/pygame/pygame/commit/a4e0f865c591980e7aa2a160a92a2c9098a678ec | title=commit by other authors|publisher=GitHub}}</ref> and is released under the [[free software]] [[GNU Lesser General Public License]]<ref name="about"/> (which "provides for Pygame to be distributed with [[open-source software|open source]] and commercial software"<ref>{{Cite web|title=Pygame Front Page — pygame v2.0.1.dev1 documentation|url=https://www.pygame.org/docs/|access-date=2021-02-26|website=www.pygame.org}}</ref>).
Pygame was originally written by [[Pete Shinners]] to replace [[PySDL]] after its development stalled.<ref name="pygame-intro"/><ref>{{cite web |url=https://sourceforge.net/projects/pysdl/ |title=pySDL sourceforge page|website=Sourceforge.net}}</ref> It has been a [[free software community|community]] project since 2000<ref>{{cite web|url=https://github.com/pygame/pygame/commit/a4e0f865c591980e7aa2a160a92a2c9098a678ec | title=commit by other authors|publisher=GitHub}}</ref> and is released under the [[free software]] [[GNU Lesser General Public License]]<ref name="about"/> (which "provides for Pygame to be distributed with [[open-source software|open source]] and commercial software"<ref>{{Cite web|title=Pygame Front Page — pygame v2.0.1.dev1 documentation|url=https://www.pygame.org/docs/|access-date=2021-02-26|website=www.pygame.org}}</ref>).


==Development of version 2==
==Development of version 2==
Line 55: Line 55:
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
import pygame, sys
import pygame, sys
pygame.init()
pygame.init()
screen = pygame.display.set_mode((1280, 720))
screen = pygame.display.set_mode((1280, 720))
Line 63: Line 64:
raccoon = pygame.transform.scale(raccoon, (200, 140))
raccoon = pygame.transform.scale(raccoon, (200, 140))
raccoonrect = raccoon.get_rect()
raccoonrect = raccoon.get_rect()
velocity = [1,1]
velocity = [1, 1]


while True:
while True:
raccoonrect = raccoonrect.move(velocity)
    raccoonrect = raccoonrect.move(velocity)
if raccoonrect.left < 0 or raccoonrect.right > 1280:
    if raccoonrect.left < 0 or raccoonrect.right > 1280:
velocity[0] = -velocity[0]
        velocity[0] = -velocity[0]
raccoon = pygame.transform.flip(raccoon,True,False)
        raccoon = pygame.transform.flip(raccoon, True, False)
if raccoonrect.top < 0 or raccoonrect.bottom > 720:
    if raccoonrect.top < 0 or raccoonrect.bottom > 720:
velocity[1] = -velocity[1]
        velocity[1] = -velocity[1]
for event in pygame.event.get():
    for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
        if event.type == pygame.QUIT:
     #screen update  
            sys.exit()
screen.fill(black)
     # screen update
screen.blit(raccoon, raccoonrect)
    screen.fill(black)
pygame.display.flip()</syntaxhighlight>
    screen.blit(raccoon, raccoonrect)
    pygame.display.flip()
</syntaxhighlight>


==Notable games using Pygame==
==Notable games using Pygame==
Line 101: Line 104:
* [news://gmane.comp.python.pygame Pygame newsgroup] [https://web.archive.org/web/20070129083639/http://news.gmane.org/gmane.comp.python.pygame (web access)] - the "official"
* [news://gmane.comp.python.pygame Pygame newsgroup] [https://web.archive.org/web/20070129083639/http://news.gmane.org/gmane.comp.python.pygame (web access)] - the "official"
* [http://pygame.renpy.org/ Pygame Subset for Android] (PGS4A)
* [http://pygame.renpy.org/ Pygame Subset for Android] (PGS4A)
* [http://pyopengl.sourceforge.net/ pyOpenGL] - Python OpenGL Bindings
* [https://pyopengl.sourceforge.net/ pyOpenGL] - Python OpenGL Bindings
* [https://pygame-sdl2.readthedocs.io/ Pygame-SDL2] - a reimplementation of Pygame APIs on top of SDL2
* [https://pygame-sdl2.readthedocs.io/ Pygame-SDL2] - a reimplementation of Pygame APIs on top of SDL2
* [https://pysdl2.readthedocs.io/ PySDL2] - a wrapper around the SDL2 library similar to the discontinued PySDL project
* [https://pysdl2.readthedocs.io/ PySDL2] - a wrapper around the SDL2 library similar to the discontinued PySDL project

Latest revision as of 13:54, 3 December 2025

Template:Short description Template:Use dmy dates Script error: No such module "Infobox".Template:Template other Script error: No such module "Check for unknown parameters".Script error: No such module "Check for conflicting parameters". Pygame is a cross-platform set 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

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

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

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

Community

Script error: No such module "anchor". Following disagreements between former core developers and the repository owner, a fork known as pygame-ce (Community Edition) was created.[12]

Script error: No such module "anchor". There is a regular competition, called PyWeek, to write games using Python (and usually but not necessarily, Pygame).[13][14][15] The community has created many tutorials for Pygame.[16][17][18][19][20]

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

Script error: No such module "Portal".

Notes

Template:Notelist

References

<templatestyles src="Reflist/styles.css" />

  1. Script error: No such module "citation/CS1".
  2. Cite error: Script error: No such module "Namespace detect".Script error: No such module "Namespace detect".
  3. Script error: No such module "citation/CS1".
  4. Script error: No such module "citation/CS1".
  5. a b Cite error: Script error: No such module "Namespace detect".Script error: No such module "Namespace detect".
  6. Script error: No such module "citation/CS1".
  7. Script error: No such module "citation/CS1".
  8. Script error: No such module "citation/CS1".
  9. Script error: No such module "citation/CS1".
  10. Script error: No such module "citation/CS1".
  11. Script error: No such module "citation/CS1".
  12. Script error: No such module "citation/CS1".
  13. Script error: No such module "citation/CS1".
  14. Script error: No such module "citation/CS1".
  15. Script error: No such module "citation/CS1".
  16. Script error: No such module "citation/CS1".
  17. Script error: No such module "citation/CS1".
  18. Script error: No such module "citation/CS1".
  19. Script error: No such module "citation/CS1".
  20. Script error: No such module "citation/CS1".
  21. Script error: No such module "citation/CS1".
  22. Script error: No such module "citation/CS1".

Script error: No such module "Check for unknown parameters".

External links

Template:Video game engines