< Back

Break Out

For those that do not know the game, Break Out is a game similar to Pong that consists of a user controlled paddle and a ball bouncing around the screen. Break Out also includes bricks (rectangles) at the opposite side of the screen as the paddle. When the ball bounces off of the bricks they disappear. The player wins the game by making all of the bricks disappear.


Setup

Create a directory assignment4 under assignments in your cs170 directory. All code for the assignment should be stored in this directory.

cd ~/cs170/assignments
mkdir assignment4
cd assignment4

Details

The paddle should be on the bottom of the screen and only able to move laterally. There should be enough bricks to arrange them in a pattern at the top of the window. After the ball bounces off a brick, the brick should disappear. That is it should no longer be drawn and should no longer be checked for intersection with the ball. When all of the bricks have disappeared the program should display a congratulatory message.

You need to have at least two types of bricks in your game: Regular and Strong. Strong bricks should behave exactly like regular bricks as far as collisions are concerned. However, they should take multiple hits to break. These bricks should change color every time they are hit, so the user gets feedback on how many more hits a brick will take.

You will be required to use inheritance in this program. Remember that inheitance is great if there happens to be multiple classes that have attributes or behaviors that are shared between them. Examine the image above carefully. I chose the shapes for each of the pieces of the game very carefully to make inheritance work incredibly well for this program.

Note that the collision detection method covered in pong does not specify how to determine which side of a brick the ball collides with. A simple solution to this problem is to make the bricks wide but not very tall and to assume that all collisions are with either the top or bottom of the brick. Also note that that the collision detection method from lab can not determine which brick is hit first, if the ball is intersecting with multiple bricks. This can be a problem because if the ball does intersect with two bricks the result will be to change the velocity twice, and the ball will not bounce. A simple solution to this problem is to arrange the bricks so that it is not possible for the ball to intersect with multiple bricks simultaneously.


Pseudocode

For next Monday, February 9th, please submit pseudocode for the main portion of your program. For any functions you define in this portion of the program, write pre and post conditions. For any class you define, define the attributes (with their types).

This is worth 20 points of your assignment grade. It does not sound like a lot, but they should be 20 easy points to get each week. Do not neglect them.


Submission

You are required to submit a tar file to http://inquire.roanoke.edu/. On cseval, there is a link for Assignment 4. You can create a tar file by issuing the following commands:

cd ~/cs170/assignments
tar czvf assignment4.tgz assignment3/

"Hacker" Prompt

  1. Better Collisions: The collisions you are using now are likely very erratic. You can easily enter not only the side of the bricks, but also the side of the paddle. A better mechanism would alter how the ball behaves depending on where it collides with the bricks and paddles.

  2. Precision Bounces: Another slight issue with the ball bouncing physics is that the angle of the ball never changes. A very good break out player usually changes the angle of the ball, to allow for the greatest score possible on each bounce. And easy way to accomplish this is by changing the angle depending on where the ball hits the paddle or the brick. A better way would be to incorporate the speed of the paddle into your computations, allowing the user to put a "spin" on the ball.

  3. Levels: After the player destroys all of the bricks on the screen, restart the game with a new, more difficult arrangement of bricks. You should develop a sane way to represent levels, so that you don't hard code the levels into your game.

  4. Bonuses: Add bricks that when hit modify the game play to make it easier for the player. For example, maybe a brick will slow down the ball, add extra balls, etc. To make it more fun, the bonuses can fall from the destroyed brick and only be awarded if they intersect with the paddle.