PYGAME
Code your own Breakout retro game
Matt Holder discovers that writing a ’70s-style classic game isn’t as simple as he first thought.
Credit: www.pygame.org
OUR EXPERT
Matt Holder has worked in IT support for over a decade, and always tries to utilise Linux alongside the other installed systems.
QUICK TIP
Get all the code for the completed game from https:// github.com/ mattmole/ LXFPaddle Smash.
Being of a certain age, we were hooked by the original Breakout. It’s one of those incredibly B simple-looking games that can become really difficult. As a challenge, we’re going to recreate Breakout, but first let’s describe the gameplay and how subsequent versions added to the original. The player moves a paddle from left to right. This paddle stays in the same vertical position on the screen and is used to ensure a ball can be bounced back up the screen. Above the paddle is an array of bricks. When these bricks are hit by the ball, they disintegrate. A level is completed when all the bricks have been hit by the ball.
It is possible to make the game more difficult by speeding up the ball, making the paddle smaller and requiring some bricks to be hit more than once before they disintegrate.
We spent many hours on an Archimedes A5000 playing Fireball 2. This game has the same gameplay as Breakout, but with extra features, such as being able to collect power-ups that drop from the bricks and give extra powers, such as two balls at once, the paddle being able to fire lasers and the ball being able to break through bricks, rather than bouncing off them. There are also power-downs, such as reversing the left-right control of the paddle and speeding up the ball to such an extent that it is impossible to keep up.
The listing in this tutorial covers the basic ideas behind the game and partial listings of the necessary data structures. Commented code is available on GitHub (see Quick Tip, left), which can be downloaded and studied, before running and playing the game.
We are using Python and the excellent PyGame library to create our project. This allows games to be written that can be windowed or full-screen, and provides all the usual features, such as keyboard and mouse control functionality, sound, screen control and the ability to draw and move sprites on the screen.