Pygame

Revision as of 07:26, 16 March 2025 by imported>Leo72 (→‎top: yet another updated release)
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Template:Short description Template:Use dmy dates {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other 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.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

HistoryEdit

Pygame was originally written by Pete Shinners to replace PySDL after its development stalled.<ref name="pygame-intro"/><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> It has been a community project since 2000<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</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 and commercial software"<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>).

Development of version 2Edit

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.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Pygame 2.0 released on 28 October 2020, Pygame's 20th anniversary.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

FeaturesEdit

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.<ref name="about"/>

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.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Applications using Pygame can run on Android phones and tablets with the use of Pygame Subset for Android (pgs4a).<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> Sound, vibration, keyboard, and accelerometer are supported on Android.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

CommunityEdit

Template:Anchor Following disagreements between former core developers and the repository owner, a fork known as pygame-ce (Community Edition) was created.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Template:Anchor There is a regular competition, called PyWeek, to write games using Python (and usually but not necessarily, Pygame).<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> The community has created many tutorials for Pygame.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Sample codeEdit

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 PygameEdit

|CitationClass=web }}</ref>

|CitationClass=web }}</ref>

See alsoEdit

Template:Portal

NotesEdit

Template:Notelist

ReferencesEdit

Template:Reflist

External linksEdit

Template:Video game engines