A modern, Pygame-based take on the classic brick-breaker. Clear all destroyable bricks while keeping the blue “hero” ball in play. Power-ups, lasers, inversion, and multi-ball keep things lively.
- Six handcrafted levels with per-level brick layouts
- Multiple brick types with unique effects and hit points
- Bonus balls, extra bats, control inversion, laser mode, and blackout mode
- Stereo-panned sound effects
- Multi-monitor aware with dynamic resizing
- Smooth intro scene with perspective-warped card and animated balls
- Python: 3.10 or newer
- OS: Windows, macOS, or Linux with a working SDL2 video driver
Installed via pip:
pygame– rendering, input, audioopencv-python– intro image warpingnumpy– array ops and masks
pygame>=2.5
opencv-python>=4.9
numpy>=1.24Note: this game is also compatible with Pygame Community Edition. If you would prefer to use that, simply replace pygame with pygame-ce in the installation process.
# 1) Create a virtual environment (recommended)
python -m venv .venv
# 2) Activate the virtual environment
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate
# 3) Ensure the 'pip' tool is up to date
python -m pip install -U pip
# 4) Install dependencies
pip install pygame opencv-python numpy# 1) Activate the virtual environment (if you haven't already done so)
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate
# 2) Start the game
python breakout.pyYou can also pass the --ratio (or -r) parameter to scale the graphics down by a specified amount, e.g.
python breakout.py -r 4will down-scale all of the graphics by a factor of four (horizontally and vertically). Higher values give more retro vibes! If your machine struggles to play Breakout smoothly at full resolution, increasing the -r parameter should reduce CPU load.
If you have multiple monitors, you can pass the --monitor (or -m) parameter to specify the desired monitor number (with 0 being the primary display).
python breakout.py -m 2If this parameter isn't passed and there are multiple monitors detected, you will see a monitor selection icon in the top-left of the intro screen. Clicking this will move the game to each monitor in turn.
- Goal: Destroy all destroyable bricks in a level without losing all of your lives.
- Lives: You lose one life each time the blue hero ball falls off the bottom. Some bricks grant extra lives.
- Levels: Clear a level to advance.
- Mouse: Move the bat horizontally
- Left click: Speed all the balls up a little
- Space: Pause or resume
- Q / Esc: Quit
- Intro screen: Move the mouse over the menu to select a difficulty, then click or press any key
Different brick types require different numbers of hits to destroy. If no brick is destroyed for a while, an extra bonus ball is introduced.
- No video device / SDL errors (Linux): Ensure you are in a graphical session and SDL2 can open a display. On headless systems set up Xvfb or Wayland appropriately.
- OpenCV import errors: Use
opencv-pythonwheels rather thanopencv. On some Linux distros you may need system OpenGL packages. - Fonts missing: The code uses the default Pygame font; if you change it (e.g. to a system font), ensure it is installed.
- DPI scaling quirks (Windows): The game queries monitor DPI in a subprocess. Ensure
pythonis on PATH anddpi_subproc.pyis accessible next to your main script.
- Pygame community (https://www.pygame.org/contribute.html) for an excellent Python module
- The very useful sfxr (https://sfxr.me/) for sound effect generation
- A nod to Arkanoid, Fireball 2 (Archimedes), and other classics
- Final level background: Rosette Nebula (Dylan O'Donnell, https://deography.com/will-you-accept-this-rose-ngc2237/)
- Thanks to ChatGPT for art assistance
Dedicated to Helena and Karen.