Danny's Block Breaker

A little block breaking game I made while learning C#

A Fun Project to Test my Skills

Using Unity, free assets, and writing in C# I made a block breaking game of the sort my sister and I used to play together as children.

Working on this project I learnt a lot of programming concepts and got some great practice with Object-Orientated-Programming.

The game uses WebGL and should run on desktop browsers. Try the game and see below for more information on how I made it!

Are you on a Phone or Tablet?

I have detected that you may be on a phone or tablet which is unlikely to support this game and so have not loaded it to spare your time and/or mobile data. If you are seeing this message incorrectly and would like to load the game, please click here to view the full block breaker page.

Making the Game

I used mostly stock assets for this project to allow me to focus on writing the code, though I did create the bricks and the paddle. I made those to specific sizes and gave the paddle two bevels on either side to allow for some control over the ball.

The game was built and compiled in the Unity Engine which provided me with a solid foundation. I really enjoyed using Unity because it encapsulates the principles of OOP so well, and all properties of objects in the editor are easily found by code. One strange part is how much of a class has to be made public, but within the wider context of the Unity Editor, this makes a lot of sense.

This meant for me that the majority of work was in writing the scripts for my game objects to interact with each other, and the way the classes tie together fits the way my brain functions perfectly.

A Strange Bug

When the game was almost complete and I was testing it, the ball would sometimes get stuck going back and forth across the screen. This seemed very strange because I reasoned that the ball would have to strike the edge of the screen at exactly 90.0 degrees, but this was happening far too often.

After researching the matter, I found very little to explain why this was occuring other than that it was a quirk of the physics engine, and that wasn't going to be something easy for me to fix. I needed to change what I was doing so that this wouldn't be a problem. I considered sloping the hit boxes as the sides a little such that a straight path back and forth was impossible, but that would affect the ball every time it struck the sides, not just when it was stuck.

My next idea was to perform a check on each collision. This was easily accomplished by taking the x and y components of the ball's velocity. If the ball is striking at an angle close to 90 degrees, then either the x or y component of it's vector will be close to zero and if so I can target that component and change it.



In my code I generate random component tweaks to kick the ball before it would get stuck, though next time I go through the code in the next iteration I will move this code so it is run only when needed. For working out when to nudge the ball, I use the public variable bounceTolerance to set the ±tolerance from the Unity Editor, allowing me to fine tine the tolerance without needing to edit my code. Since playing this build more, I believe the tolerance is still a little high as I want the ball to look as natural as possible. If you pay attention, you might be able to see it in action!

What Next?

Although this game is quite simple, I think it could be improved with the addition of a few features. For a start, more levels. This would be very easy to do by using Unity's prefab feature to quickly add what I need to each level.

With more levels it would become necessary to add lives, extending the length of the game and making it more forgiving in the long run. This could be achieved with a lives counter script linked to a UI text object.

One more thing I would like to add to the game, but would take a little more time and consideration to impliment, is power-ups. Power-ups could have a random chance of dropping from a destroyed brick and if caught by the paddle apply boons such as a wider paddle, an extra life, or even slow motion.