BreakEm

Top  Previous  Next

This month I have decided to write the code for a 3D breakout game: it includes 5 levels, code for score, lives, several bricks and so much more!

 

aum52_breakem1

 

Let me explain what each brick does:

 

aum52_breakem2

 

That's your regular brick. Hit it with the ball and it will disappear, adding points to player's score.

 

aum52_breakem3

 

This brick expands your paddle.

 

aum52_breakem4

 

This brick shrinks your paddle.

 

aum52_breakem5

 

This brick increases the speed of the ball.

 

aum52_breakem6

 

This brick decreases the speed of the ball.

 

aum52_breakem7

 

This brick gives you an extra paddle (extra life).

 

 

 

 

 

 

The one above is the invisible brick ;). You can't see it, but it will appear after you hit it with the ball for the first time, disappearing after you've hit it the second time.

 

You can see that we've got quite a few bricks here; you can (and you should!) add even more special bricks.

 

Here are a few code highlights:

 

1) Each brick increases a global brick counter, which is displayed on the screen; this way, you will be able to tell if a certain level contains invisible bricks or not.

 

2) I have added two mechanisms that prevent the ball from getting stuck in a wall, in a corner or in player's paddle, by tracking the distance that was covered by the ball in the last frame using c_move.

 

3) The player loses a life is the coordinates of the ball on the x axis go below 550 quants. Change this value until it fits your needs if you are going to use a different level as a base.

 

4) The ball uses some randomness; this makes the gameplay more attractive (surprising would be a better word, I guess) and avoids situations where a ball would bounce from one wall to the other forever, making the player stare at the screen without being able to do anything.

 

5) I am not allowing the ball to bounce at pan angles that are too close to -90 and 90 degrees (a boring thing to watch); if the bouncing angle is in the (-100...-80) and (80...100) degrees range, it will be set to one of the values that are given by the margins of these intervals.

 

aum52_breakem8

 

6) Moving on to the following level is done by calling function main() again and again. The variable named level_number must be set to the desired level number before running main.