This is a simple implementation with Python 3 and PyGame of the classic Breakout game. The purpose is to serve as a demo game for a series of articles on building games with Python 3 and PyGame:
- Building Games With Python 3 and Pygame: Part 1
- Building Games With Python 3 and Pygame: Part 2
- Building Games With Python 3 and Pygame: Part 3
- Building Games With Python 3 and Pygame: Part 4
- Building Games With Python 3 and Pygame: Part 5
- Simple generic GameObject and TextObject
- Simple generic Game object
- Simple generic button
- Config file
- Handling keyboard and mouse events
- Bricks, paddle and ball
- Managing paddle movement
- Handling collisions of the ball with everything
- Background image
- Sound effects
- Extensible special effects system
The prerequisites are:
Then clone the repository and type:
pipenv install
You should see something like:
$ pipenv install
Creating a virtualenv for this project…
Pipfile: /Users/gigi.sayfan/git/pygame-breakout/Pipfile
Using /Users/gigi.sayfan/.pyenv/versions/3.8.0/bin/python3 (3.8.0) to create virtualenv…
⠙ Creating virtual environment...Using base prefix '/Users/gigi.sayfan/.pyenv/versions/3.8.0'
New python executable in /Users/gigi.sayfan/.local/share/virtualenvs/pygame-breakout-mgkKDQCD/bin/python3
Also creating executable in /Users/gigi.sayfan/.local/share/virtualenvs/pygame-breakout-mgkKDQCD/bin/python
Installing setuptools, pip, wheel...
done.
Running virtualenv with interpreter /Users/gigi.sayfan/.pyenv/versions/3.8.0/bin/python3
✔ Successfully created virtual environment!
Virtualenv location: /Users/gigi.sayfan/.local/share/virtualenvs/pygame-breakout-mgkKDQCD
Installing dependencies from Pipfile.lock (b269cc)…
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 1/1 — 00:00:08
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
To run the game type:
pipenv run python breakout.py
I used some color constants I found in this nice article: https://www.webucator.com/blog/2015/03/python-color-constants-module/