On this page
How to use it#
- Tick the components you want. Dependencies are handled automatically: collecting sprites needs both a player and sprites.
- Adjust properties such as window size, colours, speed, sprite count and timer interval.
- Copy, Download .py, or Run online in Pygame Online.
Components#
| Component | What it generates |
|---|---|
| Keyboard-controlled player | A Player sprite moved with the arrow keys or WASD, kept inside the window. |
| Sprites in a group | A Collectible sprite class and a group of them at random positions. |
| Collect sprites | spritecollide between the player and collectibles, removing them and counting a score. |
| Text | A font and a label showing the title or the score. |
| Background shapes | A draw_scenery() function with a ground strip, a sun and a line. |
| Mouse clicks | Records click positions, draws markers and prints the coordinates. |
| Timer event | A custom event posted with pygame.time.set_timer, which spawns new collectibles. |
| Browser-compatible loop | The asyncio structure needed for browsers; otherwise a classic main() function. |
Default output#
The default settings generate a small game: move the yellow square to collect blue circles while the score counts up. It's deliberately simple so you can read all of it in a few minutes, and it uses the same structure as the tutorials: constants at the top, sprite classes, then a single loop with events, updates and drawing.
Every combination of components (256 of them) was generated and run with pygame-ce and pygame during testing, with scripted keyboard and mouse input.
Next steps#
- Replace the coloured shapes with images: see images and sprites.
- Add a timer and a game-over screen: see menus and game states.
- Save the best score: see score system.