# CompSci 4 Java for Video Games

## 250 points, due 11:30pm March 9, 2006

### Introduction

Breakout is a popular extension to the game of Pong that has been described as "the ultimate in Pong". Breakout was designed by Steve Jobs, CEO of Apple Computer. But it was Job's friend Steve Wozniak who did most of the work on Breakout, not Jobs. However Jobs received a \$5,000 bonus for the work but told Wozniak it was only \$700 and gave Wozniak his "50%" --- \$350. Years later this truth would come out and it would add to the already increasing friction between the two which eventually lead to Steve Wozniak quitting Apple.

### Requirements

In breakout a ball bounces around the screen and destroys blocks as it bounces into them. The ball can bounce off of the top and sides of the screen. If the ball moves off the bottom of the screen, the player loses a life. The player controls a paddle at the bottom of the screen to block the ball from moving off the bottom. If the player misses blocking the ball three times, the game should end with the player as the loser. If all the blocks are cleared from the screen, the game should end with the player as a winner.

You will be given a basic version of the game in which a ball starts in the center of the screen and falls towards your paddle. There will also be one block on the screen that will disappear when hit. The paddle's motion is controlled by the mouse. There are two classes that make up this game: `Breakout` (the game) and `ProjectileTracker` (which moves the ball each step of the game). You should not need to modify the tracker class.

In the class `Breakout`, you should add code to make a collection of blocks in rows across the top of the screen and indicators that show how many lives the player has remaining and how many blocks have been cleared (i.e., a score). Then you should add code to detect when the player loses a life and subtracts it from their total, resets the ball to the center of the screen. If it is the third time, the game should end and display a message that declares the player a loser. You should also add code that adds to the player's score each time a block is hit and disappears. If all the blocks have been cleared, the game should end and display a message that declares the player a winner.

Note, you will have to spend some time choosing fixed values for the size of the paddle, speed of the ball, and size of the blocksin order to ensure the game is fun to play. Include some discussion of why you chose the values you did in your code's comments. Note, you do not need to do anything more to implement bouncing than is already given in the code you download for the project.

### Extra Credit

Once you have the basic game working, you can add a variety of features to make your game more fun to play (listed below roughly in order of difficulty):

• Give the blocks different colors based on some kind of pattern (e.g., each row is the same color). To get full extra credit for this, you must still create the blocks using a loop (rather than setting each block's color in a long sequence of statements). Note, you may want to create a collection of colors so that you can access them within your loop (e.g., one color for each row you create).
• Instead of a solid wall of blocks, place the blocks in a pattern (e.g., a "V", or a diamond). Again, you must use a patterns that you can create using a loop rather than placing each block in a sequence of statements.
• In addition to standard blocks, create special blocks that react differently when hit (e.g., require more hits to disappear or create an extra ball). Note, you may want to store these special blocks in separate collections to make it easier to check for. Also, if your special block needs to remember something (e.g., how many times it has been hit), you may need to create separate class for it that extends `Sprite`.
• When the collection of blocks is completely cleared, start a new level and create another pattern of blocks, instead of ending the game. To make each level different, you might make each block worth more points, each pattern of blocks different, or the ball move faster each time. In this case, it may no longer be possible to win the game (or there may be a fixed number of levels). To implement levels successfully, you will need to be very careful about defining variables to control different values in your game (e.g., ball's velocity or score for each brick).

Please include, on your applet website, a description of the extra credit features you attempted so that there is less chance we miss them when we are grading your assignment.

### How to

1. Using Eclipse, snarf the project breakout which contains the beginning code for the game.
2. Run the program by running `Breakout`. You can run `Breakout` either as an applet or an application.
3. When done, submit your assignment using Eclipse as breakout.
4. Update your web page for this homework by posting your applet.