This is a terminal based brick breaker game. Zero GUI. The game physics makes use of a 2D grid that represents the board, with each element of the board being a single character. In each iteration of the game loop, the board is updated based on user input and other factors within the game and the new board is printed to the screen.
The only non-core python library used was colorama to add color to the text.
Install colorama if you haven't already:
pip3 install coloramaThen cd into the root directory of this project and run
python3 main.pyto launch the game.
Use a and d or the left and right arrow keys to move the paddle. Use space to launch the ball. Your target is to destroy all the colored bricks on the screen. To do damage to a brick, hit it with the ball.
There are 6 types of bricks in the game. Green bricks take 1 hit to destroy, Yellow ones take 2 and Red ones take 3. White bricks are unbreakable under normal circumstances. Blue bricks are called exploding bricks. Upon hitting one of them, it not just destroys the brick, but all its neighboring bricks as well. If one of its neighboring bricks is also an exploding brick, it triggers a chain reaction. The last is a Rainbow brick. This bricks keeps changing its color and hardness to one of the first three bricks. Once the brick is hit, it stops changing its color and randomly becomes one of the standard three bricks.
If the ball hits the bottom edge of the screen, you lose a life. You lose if you lose all your lives before destroying all colored bricks.
On destroying a brick, a random powerup may appear and follow a parabolic trajectory from the brick that was broken. Collect it with your paddle to gain the powerup. The powerups are:
E: "Expand Paddle" make the paddle largerS: "Shrink Paddle" makes the paddle smallerM: "Ball Multiplier" (a.k.a Multi-ball) makes a copy of each ball currently in playF: "Fast Ball" increases the speed of each ball in play 1.5 timesT: "Thru Ball" ball goes through any bricks it touches, including unbreakable onesG: "Paddle Grab" every time the ball hits the paddle, you can launch it at will.L: "Laser Paddle" the paddle gets equipped with lasers on either side that can be fired by pressing the up arrow, with a cooloof of 0.5 seconds.
Each powerup lasts for 15 seconds (except for Ball Multiplier, which has no time duration).
Every time you do damage to a brick, your score increases by 1. If you directly destroy a brick (using Thru-ball or an exploding brick), you get a score equivalent to its strength (the strength of an exploding brick itself is 1). If you manage to destroy an unbreakable brick (using Thru-ball or an exploding brick), your score increases by 5 points.
Every 30 seconds into a level, the bricks come down one step. If any brick gets to the same height as the paddle, the game is over.
There are two standard levels where the paddle must break the bricks to progress to the next level. The third level is a Boss Battle where you need to destroy a Boss Enemy. The Boss is a UFO that follows the paddle and drop bombs on it. Hitting the boss will reduce its health. If the ball hits the bottom edge of the screen, the paddle loses one life and its position is reset and the UFO stops dropping bombs till the paddle launches the ball again. If a bomb hits the paddle, the paddle loses one life, but the game continues as it is, without the paddle getting reset. The UFO has 20 health. If its health falls below 16, the UFO deploys a protective layer of Green bricks under it and shoots the ball out from its protected area towards the paddle. These bricks can be broken by the ball, but don't yield any powerups. If its health falls below 6, the UFO deploys a protective layer of Red bricks, which can again be damaged and broken by the ball. Again, the ball is projected out from its protected area towards the paddle. The bombs from the UFO however, can pass directly through any bricks, and hit the paddle, so it would be best to dodge them.
-
The game is highly customizable as all configuration variables of the game have been stored together in a
config.jsonfile. When the game is launched, the file is read and configuration variables are set in the game using a helper function. -
The brick layout is highly customizable. Specify the brick layout in a 13x13 matrix in
brick_layout.txt. The allowed characters are.representing an empty space,1,2and3representing bricks of respective strengths,4representing an unbreakable brick and5representing an exploding brick. -
A custom Input method has been used that allows using arrow keys to control the paddle as well as the
aanddkeys. -
Power ups appear with a 50% chance when a brick is broken. Which power up appears is randomly chosen. Each powerup is represented as a collectable that falls downwards from the location of the brick that was broken. If not collected, it goes out of bounds and is removed from the game.
-
If a powerup that is already active is collected again, the duration for that powerup will be topped up to its original duration.
-
For the "Expand Paddle" and "Shrink Paddle" powerups, the latest collected powerup will replace the existing one and duration will be topped up to the original duration.
-
The "Ball Multiplier" is the only powerup that doesn't have a duration.
-
Though not mentioned as a requirement, diagonal collision has also been handled. If the ball hits a brick or the border of the board at a corner, both its
xandyvelocities will be flipped. -
When the the "Ball Mutliplier" powerup is picked up, evey ball already in play is cloned. A clone of a ball is an exact copy of the ball, including all the same powerups currently in effect to the original ball. The only difference in a clone is that its
xdirection velocity is negative of that of its source ball. -
Each time the ball hits a brick and does damage to it, the score is increased by
1. But in while the "Thru-ball" powerup is active, every brick that is destoryed adds an amount equal to its strength to the score. Breaking an unbreakable brick while in "Thru-ball" mode will add4points to the score. -
A round is over when the all the balls have gone out of bounds, i.e., they have hit the bottom edge of the board. In this case, the player loses a life.
-
The game is over either when the player loses all his lives or all breakable bricks in the game have been destroyed.
-
A player can skip a level by hitting
sat any point.
-
Inheritance: Each Brick type has its own class, each of which inherit some generic brick properties and methods from a parent
Brickclass (Refer tobrick.py) -
Polymorphism: Each Powerup is unique and has unique effects, but have a generic template. They are created, collected, activated and deactivated. What happens in each of these steps is unique to the powerup itself. Thus each powerup has its own class which inherits from a general
Powerupclass. Each power up class then modifies the methods in the parent class as per its own requirements (Refer topowerups.py). -
Encapsulation: Every game object is represented as instance of a class. The actions and properties of the object are defined by the class methods and variables (Refer
ball.py,board.py,brick.py,paddle.py,powerups.py). -
Abstraction: The behaviour of game objects are hidden from the end user by using methods. For example, making an object move is as simple as called its
.move()method (Refer tomain.py), or cloning a ball is just requires a call to the.make_twin()method.