CPSC 170 Post Lab 1
Break Out
Due Before Lab on Tuesday, January 24th

bricks

For this assignment you will modify your pong program from lab one to make the game 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.

Details

You can use the Pong code that we created in class for reference. Be sure your program is named Break Out and not Pong. Once you have the program working like a game of Pong, modify it by doing the following:

  1. Begin by adding to the panel class an instance variable that is an array of Sprites that represents all of the bricks. In the constructor initialize the array and all of the Sprites in it. Add to the paintComponent method a loop that iterates over the entire array of sprites and for each sprite, draws it. Test your program before proceeding. It should display all of the bricks, but the ball should pass right through them.
  2. Next, add a loop to the actionPerformed method that uses the overlap methods of the sprite class to test if the ball intersects with any of the bricks and on which side. If the ball does, then it should change the direction based on the side that it hit. If the ball intersects multiple sides, compare the amount of overlap with each of the sides. The ball should change direction as if it only intersected with the side with a smaller overlap. If the ball intersects with multiple sides and the amount of overlap is the same, the ball should change direction as if it only intersected with one side, but it does not matter which. Test your program before proceeding. The ball should bounce off of the bricks, but the bricks should not disappear.
  3. Next, add an instance variable to the sprite class that specifies if a sprite is visible. Modify the loop in the paintComponent method to only draw a sprite if it is visible. Modify the actionPerformed method to only perform collision detection if the sprite is visible. Finally, add to the if statement that tests if the ball hits a brick to set the brick that was hit to not be visible. Test your program, the bricks should disappear after being hit by the ball.
  4. Finally, modify the program to print a congratulatory message when all of the brick have been hit and made invisible.


Submission: Submit your code as a zip file with your name as the zip file name on the course Inquire site.

Extra

Bonuses

Add bricks with different colors that when hit modify the game play to make it easier for the player. Some examples are, slowing down the ball, growing the paddle, growing the ball, or adding an extra ball. To make it more fun the bonuses can fall from the destroyed brick and only be awarded if they intersect with the paddle.

Spin

The game can be made more fun by giving the user more control over how the ball bounces off of the paddle. In order to do this you will need to modify the ball's direction without modifying its speed. This is difficult when both the speed and direction are specified with velocity. Change the ball's instance data to be direction (the angle in radians from the x-axis the ball is traveling) and speed (the number of pixels per frame of animation). When the ball hits the paddle use the velocity of the paddle to modify the angle that the ball bounces. The faster the paddle is moving the more the ball's angle should change.