Blockbreaker
Tags: showdev, python
Published: 2021-01-31 13:43:48

---
description: "A Python program based on the classic Brickbreaker game created as a competition entry during my first year at university. Spoiler, I won first place!"
---
During my first year at the University of Portsmouth (2015), I had the opportunity to take part in a Python programming competition. To compete, we had to extend one of two base programs into a game. At the time I had only been programming for half a semester, so it appeared to be the perfect opportunity to develop software outside of university coursework. My entry was titled "Blockbreaker", a re-implementation of the classic game Brickbreaker. The competition was a success and I won first place 🥇.

<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/i/4kpsddmis5abx144yrim.png" alt="Blockbreaker game screen">
  <figcaption>Game screen</figcaption>
</figure>

##Original brief
This is an individual competition – group entries are not allowed. Use only Python and the graphics module. Don't write (object-oriented) classes and do not use non-standard libraries such as PyGame – any modules you use apart from John Zelle's `graphics.py` must be part of the standard Python 3 distribution. However, if you want to add sound, I suggest using the `winsound` module (this only works on Windows, but you can assume that we will use a Windows computer to run your program). Do not re-write the game completely – it should still involve bat(s)/ball or an android eating apples (but of course, it could do other things as well!). Keep to the spirit of the unit and the competition, and make sure that your game would not offend anyone.

<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/i/h27v3r8bxobcx9fn4e6u.png" alt="Blockbreaker game over screen">
  <figcaption>Game over screen</figcaption>
</figure>

##Technical Details
Blockbreaker is written in Python (2.7 but works with 3) and is made up of 3 types of components - the bat, walls and the blocks themselves. It predominately uses `Lists` to keep track of game items such as blocks and score, as every block has a different value. The game is constantly calculating whether the ball has hit any component and determines whether it needs to alter the trajectory of the ball. Matching the original Brickbreaker, when a certain amount of blocks are hit, the game levels-up, increasing the ball speed and altering the colour of the blocks. For creating the Graphics, it uses [John Zelle's `graphics.py`](https://mcsp.wartburg.edu/zelle/python/graphics.py) which was used heavily in University coursework, and a requirement for the competition. It also uses built-in Python modules to read/write the high scores file, control the speed of the ball and randomise the direction of the ball when it hits a surface. The source code is [available on Github](https://github.com/james-wallis/blockbreaker).

<figure>
  <img src="https://dev-to-uploads.s3.amazonaws.com/i/tiqpjto83c9mbresce8z.gif" alt="Blockbreaker animation on startup">
  <figcaption>Block animation on startup</figcaption>
</figure>

[The source code for Blockbreaker is available on GitHub.](https://github.com/james-wallis/blockbreaker)