Pygame is a
cross-platform
Within computing, cross-platform software (also called multi-platform software, platform-agnostic software, or platform-independent software) is computer software that is designed to work in several Computing platform, computing platforms. Some ...
set of
Python modules designed for writing
video game
A video game or computer game is an electronic game that involves interaction with a user interface or input device (such as a joystick, game controller, controller, computer keyboard, keyboard, or motion sensing device) to generate visual fe ...
s. It includes
computer graphics
Computer graphics deals with generating images and art with the aid of computers. Computer graphics is a core technology in digital photography, film, video games, digital art, cell phone and computer displays, and many specialized applications. ...
and sound
libraries
A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
designed to be used with the Python
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
.
History
Pygame was originally written by
Pete Shinners to replace
PySDL after its development stalled.
It has been a
community
A community is a social unit (a group of people) with a shared socially-significant characteristic, such as place, set of norms, culture, religion, values, customs, or identity. Communities may share a sense of place situated in a given g ...
project since 2000 and is released under the
free software
Free software, libre software, libreware sometimes known as freedom-respecting software is computer software distributed open-source license, under terms that allow users to run the software for any purpose as well as to study, change, distribut ...
GNU Lesser General Public License
The GNU Lesser General Public License (LGPL) is a free-software license published by the Free Software Foundation (FSF). The license allows developers and companies to use and integrate a software component released under the LGPL into their own ...
(which "provides for Pygame to be distributed with
open source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use and view the source code, design documents, or content of the product. The open source model is a decentrali ...
and commercial software").
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.
Pygame 2.0 released on 28 October 2020, Pygame's 20th anniversary.
Features
Pygame uses the
Simple DirectMedia Layer (SDL) library, with the intention of allowing
real-time computer game development without the
low-level mechanics of the
C programming language
C (''pronounced'' '' – like the letter c'') is a general-purpose programming language. It was created in the 1970s by Dennis Ritchie and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of ...
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
A high-level programming language is a programming language with strong Abstraction (computer science), abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language ''elements'', be ea ...
, such as Python, to structure the game.
Other features that SDL does have include vector math,
collision detection, 2D sprite
scene graph management,
MIDI
Musical Instrument Digital Interface (; MIDI) is an American-Japanese technical standard that describes a communication protocol, digital interface, and electrical connectors that connect a wide variety of electronic musical instruments, ...
support, camera, pixel-array manipulation, transformations, filtering, advanced freetype font support, and drawing.
Applications using Pygame can run on Android phones and tablets with the use of Pygame Subset for Android (pgs4a). Sound, vibration, keyboard, and accelerometer are supported on Android.
Community
Following disagreements between former core developers and the repository owner, a fork known as pygame-ce (Community Edition) was created.
There is a regular competition, called PyWeek, to write games using Python (and usually but not necessarily, Pygame). The community has created many tutorials for Pygame.
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
while True:
raccoonrect = raccoonrect.move(velocity)
if raccoonrect.left < 0 or raccoonrect.right > 1280:
velocity = -velocity raccoon = pygame.transform.flip(raccoon,True,False)
if raccoonrect.top < 0 or raccoonrect.bottom > 720:
velocity = -velocity 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
* ''
Frets on Fire''
* ''
Dangerous High School Girls in Trouble!''
See also
*
Cocos2d
*
Panda3D
*
Pyglet
Pyglet is a Library (computing), library for the Python (programming language), Python programming language that provides an Object-oriented programming, object-oriented application programming interface for the creation of games and other multim ...
Notes
References
External links
*
* [news://gmane.comp.python.pygame 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
{{Video game engines
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