Day 87 of the 100 Days of Code Course. The goal for the day was to re-create the Breakout video game.
Turtle Graphics is used to create the GUI elements in this project. This includes the following:
- Setting up the screen
- Setting up the scoreboard
- Setting up the bricks
- Setting up the ball
- Controlling the GUI elements
Time’s sleep method is used to control the movement speed of the ball.
Random is used to set the ball's heading in a random position when it first spawns.
The Ball.py file controls the creation of the Ball class.
Along with the creation of the ball object, the ball’s movement is managed in this file, including when the ball bounces off walls, bricks, and the paddle. Originally, I was going to use the bounce method covered during the Pong lessons of the course by using x & y coordinates of 10 and -10 and inversing them when contact is made. However, I wanted to add the capability to produce obtuse and acute angles when the ball contacts the paddle. A different method was used to achieve the desired bounce effects as depicted in the screenshot below.
The ball file also contains the reset method, which resets the ball to be directly above the paddle when that method is called.
The bricks.py file is used to render the bricks into the necessary position.
The bricks file contains three separate-sized bricks (small, medium, and large). The file is also responsible for positioning the bricks in the appropriate position on the game screen.
Rows 1-3 would be used for level 1, with each additional level adding a new row to the screen.
Main.py ties everything together.
This includes importing the necessary modules and classes, creating functions for each level, setting up the objects, and carrying out the game play. The Project Walkthrough section will provide more information on what gets carried out in main.py.
Paddle.py is responsible for creating the paddle object, controlling its movement, and resetting the paddle.
Scoreboard.py manages the Scoreboard class. This includes keeping track of the current level, number of bricks destroyed, and number of lives the user has.
Additionally, the Walls class is used to draw the gray border on the edge of the screen when the game starts.
This project relies heavily on object-oriented programming. The project starts by importing the necessary modules and classes from the other files described above.
The main.py file also has several functions that call some of the functions and methods created in the other files. Here is a brief description of the functions created.
- Reset_ball_paddle: Resets the ball and paddle to their starting positions.
- Level functions: The program has six levels. Each level calls on the Row functions from the bricks.py file. Once a level is cleared, subsequent rows are appended in the game. The row’s bricks are appended to lists based on the brick’s size.
After the functions are defined, the next step is to set up the objects used in the game, which include:
- Screen
- Scoreboard
- Walls
- Paddle
- Ball
- Bricks (rows defined by the current level)
With the game setup, the game is ready to begin!
While the game is on, the game evaluates what level the user is currently at. This determines what number of bricks get displayed or if the user has won the game. Additionally, the program checks to see if the user has any lives. If the user is out of lives, the game is over.
While the game is true and the level has been determined, the ball is hit off the paddle and bounces off bricks or the wall. This mechanism is repeated until all the bricks have been cleared or the user is out of lives. Once all the bricks get cleared, the user moves onto the next level, additional bricks are rendered, and the ball's speed is increased.
Note: As more bricks are rendered on the screen, the ball's movement slows down. I tried a few things, including changing the turtle's speed and clearing the screen, but those did not have desirable results. On level five, there are 108 bricks that are rendered and on the screen, and on level six, there are 166 bricks. The only thing I noticed that improved the ball's movement speed was when the bricks were hit and moved off-screen (moving their position to 1,000, 1,000).
Additional screenshots for this project can be found in the screenshots folder.

