Modify the Block Breaker game in Exercise 22.13 as follows: a) When the ball hits the paddle,
Question:
Modify the Block Breaker game in Exercise 22.13 as follows:
a) When the ball hits the paddle, change its dx value and direction based on the intersection point. For example, assume the paddle has three “zones.” If the ball hits the left zone, dx should be set to -5 so the ball moves to the left by 5 pixels each time its location changes. If the ball hits the right zone, dx should be set to 5 so the ball moves to the right by 5 pixels each time its location changes. If the ball hits the center zone, it should keep moving in the same x direction by 2 pixels each time its location changes.
b) Add multiple levels. In each level, the ball’s speed should increase by 10% and the size of the paddle should decrease by 5%.
c) Provide a continuous mode in which as the user clears a row, the existing blocks move down a row and a new row of blocks is added at the top.
Exercise 22.13
When the app begins executing, the ball is sitting on top of the paddle, which is located at the bottom-center of the window. The user clicks the mouse to set the ball in motion toward the blocks—that is, its dy value is initially negative. When the ball hits a block, that block should be removed from the screen and the ball should bounce back towards the blocker—that is, its dy value becomes positive, similar to bouncing off the top of the Pane. If the ball hits the left or right side of the Pane it should bounce in the opposite direction.
To move the ball toward the blocks again, the user must move the paddle (by moving the mouse left or right in the window) so the ball will bounce off the paddle to change directions. The dx value should change only when the ball hits the Pane’s left or right side. For this version of the app, set the dx and dy values to 2. You can test for collisions between the ball and the blocks or paddle by using the Shape class’s static intersect method.
The user should begin with three lives—if the ball misses the paddle and falls off the bottom of the screen, the user should lose a life. The game ends when the user either clears all the blocks or loses all three lives. Award points for each block that’s destroyed with more points for blocks in the higher rows.
Step by Step Answer:
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates