Pygame game projects

Ten complete, original games, each in one Python file with no assets to download. Read the code, run it, change it, or play it in your browser.

All game projects

Snake game screenshot: a blue snake on a checkered board heading towards a yellow pellet

Snake

Grid movement, a growing tail and buffered turns.

BeginnerRuns in browser
Pong screenshot: blue player paddle, yellow computer paddle, white ball and a 4 to 3 score

Pong

Paddles, rebound angles and a beatable computer opponent.

BeginnerRuns in browser
Breakout screenshot: rows of coloured bricks with gaps, a ball and a paddle

Breakout

Brick grids, side-aware bounces, lives and levels.

IntermediateRuns in browser
Maze Runner screenshot: a generated maze with a green hint path from the blue player to the yellow exit

Maze Runner

Random maze generation and breadth-first search.

IntermediateRuns in browser
Tic-tac-toe screenshot: a board with two X and two O marks and the score tally below

Tic-tac-toe

Two-player mode and an unbeatable minimax computer.

BeginnerRuns in browser

How to use these projects#

Every game is a single file you can read from top to bottom, organised the same way: settings at the top, classes for game objects, a Game class that handles events, updates and drawing, and a short main() loop. Once you understand one, the others are easy to follow.

  • To play, click Play in browser on a project page, or download the .py file and run it with Python after installing Pygame.
  • To learn, read the "How it works" section first, then the source. Each page lists the concepts the game teaches.
  • To build your own, pick an idea from the "Ideas to extend it" list. Small changes such as a new power-up or a second level are the best way to learn.

All games were tested with pygame-ce 2.5.8 and pygame 2.6.1: automated tests drive the actual game code (moving, scoring, colliding, winning and losing) and run each game's real main loop. Graphics are drawn in code, so there are no image files to manage and you are free to replace them with your own art.

License#

The game source code on this site is released under the MIT license, so you may use it in your own projects, including commercial ones. Pygame itself is licensed under the LGPL. See licenses and attribution.

↑ ↓ to moveEnter to openEsc to close