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: