Linux Format

Blast apart classic Breakout gaming code

Credit: www.pygame.org

We’re continuing our recreation of the classic game of Breakout. In this game, the player W controls a paddle, which is moved across the screen, left and right, so that a ball can be bounced between the paddle and a number of bricks that are rendered on the screen. The collisions between the ball and the bricks causes damage, and bricks can then be destroyed. The game contains a number of power options, such as speeding up the ball, creating extra balls, creating an extra paddle, and a laser, which fires laser pulses at the bricks, which then causes them to disintegrate.

Part one of the article, LXF306, described the basic mechanics and explained the majority of the classes that are being used to describe the various objects. In this part of the article, we are creating the in-game logic, which is used to detect keypresses and move the paddle. The source code of the game is available on GitHub, and as well as following along with the article, this commented code is required to get the game to function as intended. The following code sample shows an extract from the Bricks.py file:

You’re reading a preview, subscribe to read more.

More from Linux Format

Linux Format5 min read
Tips For Managing Docker Containers
Everyone knows how containers revolutionised application building and deployment. Using a E disposable stack of containers that make up an app that aren’t using the docker-compose command to manage the stack are missing a trick. It allows the shippin
Linux Format3 min readSecurity
ParrotOS
A security focused operating system that is well suited to the Raspberry Pi 4 2GB and upwards, but not Pi 5 for now. ParrotOS provides a plethora of security auditing tools for both red and blue team members. This is a great distro for learners and n
Linux Format2 min read
Automatic Tracking
TimeSlotTracker has activity monitoring and this includes an optional facility to take screenshots and T place them in a user-defined directory. However, this isn’t the type of intricate user monitoring that some of the other options offer. Idle dete

Related