Brick Breaker Game

Created June 22nd, 2014. Built on the Raspberry Pi.

I remember playing brick breaker type games when I was a kid and wanted to give Devon the same experience. As I started building this game, I realized how many cool features we could add later such as special bricks and power boosts. We started with what we learned from building Pong previously.

Devon didn’t really get what I was trying to do on this one so he kept trying to take things a different direction. I eventually had to work on it myself a bit because I was really getting stumped on getting the angles right when the ball hits a brick or bounces off the paddle. Eventually I got it working and he enjoyed playing it, but he hasn’t shown enough interest to add more features yet.

First we have the stage code which handles showing the correct costume and configuring global variables.


These are the sprites in use. Notice how each brick is its own sprite.


The paddle code is super simple as we keep the complex logic in the ball (taking queues from the Pong Game we already created).


The brick code is also pretty simple for keeping track of the score and hiding the brick if it gets hit.


And now for the details of the ball code. It took a lot of trial and error to figure out how to handle the angles correctly for sending the ball back away from the bricks or up from the paddle. Devon and I wrote some triangles on paper and played around with different options. Once we had the equations figured out (Bricks: 180 – abs(direction), then put the direction back in, either positive or negative), Devon excitedly read them back to me as I plugged in the code.

Just like the pong game, we used the super helpful “if on edge, bounce” command to handle the walls and the ceiling.

We did some fun stuff with the paddle edges, each having a different color. If hitting the edge, we randomly change the angle by +-10 degrees. In addition, if you hit the right side of the paddle while traveling left, it will bounce the ball back to the right again (same thing for the other side).

Another little gotcha we ran into is if you trigger a hit, you need to force the ball to move away so it doesn’t trigger again and head back the direction it came (that’s what the move speed*2 steps call is for).


Play some Brick Breaker by downloading the full Scratch file. You can also use it as your starting point to add even more cool features.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s