Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with an assignment that creates a game, that has a paddle and a ball. The ball will bounce off the paddle or

I need help with an assignment that creates a game, that has a paddle and a ball. The ball will bounce off the paddle or walls and can hit the blocks. If it hits the blocks, they disappear.

These are notes provided:

You may add additional classes and/or methods. For instance, I have a private helper method in my Breakout class called updateBall that call's the Ball's move method and checks for collisions against the other parts. Another example is the ballHitBlocks method which first checks to see if a ball hits one or more of the blocks, noting which part of the block the ball hit (HINT: uses whichPartHit) and then sets one or more flags on whether to bounce vertically and/or horizontally. Then after that pass through all the blocks, it removes the blocks both from the root of the scene graph as well as the collection of blocks.

On the class diagram you will notice on the "has a" link between Breakout and Block an asterisk, which means that Breakout has 0 or more blocks. The way that is implemented is using some sort of collection, e.g. array, 2d-array, or something in the java.util (Links to an external site.)Links to an external site. package. HINT: In my implementation I use a java.util.ArrayList (Links to an external site.)Links to an external site.. This is helpful especially because when it comes time to remove any blocks hit by the ball (on a given KeyFrame update) you can use the removeIf (Links to an external site.)Links to an external site. method that takes a lambda.

You should have no magic numbers in your code (except if you need to divide by 2). Your code should be written making use of the constants defined in the Constants interface.

Having the ball bounce off the blocks. First note that it is possible for the ball to hit up to 3 blocks at a time. The way the ball bounces off, depends on which part of the brick the ball hit. If the ball hit the left or right side of the block then you flip the horizontal velocity. If the ball hit the top or bottom of the block, you flip the vertical velocity. If the ball hit the corner of a block, you flip both. Of course, if you hit multiple blocks in different places then you will need to change the direction accordingly. The good news is that the logic for determining where the ball hit a particular block is given to you in the method whichPartHit. Notice it returns an enum, BlockSide.

Bouncing off the paddle, can change the ball's horizontal velocity. Basically, you subtract the middle horizontal point of the paddle from the middle point of the ball and then scale (divide) that result down and set it as the new horizontal velocity of the ball. Make sure to scale it enough so that the horizontal velocity does not end up too fast.

Like shown in the demo video, you must provide the instance variables _bounceBottom and _testTop. When _bounceBottom is true, the ball will bounce off the bottom of the screen instead of falling through and causing the game to end -- this will make it easier during grading. When _testTop is true, the ball will start out above the bank of blocks -- again, this will help check that your code (especially for bouncing) is working properly.

Note that the Block class has overridden setX and setY methods -- they add Constants.BLOCK_BORDER to the x and y component respectively.

Extra Credit

This assignment is rife with opportunity for extra credit. Here are some things you can implement and the amount of extra credit they will bring.

2 points - scoring (must be displayed)

2 points - refreshing the board when all the blocks have been hit

2 points - adding lives (must be displayed)

2 points - adding ability to replay the game after it has been lost

2 points - adding requirement to hit key or click mouse button to start (must show a label saying what to hit to start, and that label must be removed once started)

2 points - adding pause/unpause functions (when paused, must show a label denoting that the game is paused, label must be removed once unpaused)

3 points - adding different sound effects for ball hitting blocks, paddle, walls

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

Students also viewed these Databases questions

Question

Explain the various methods of job evaluation

Answered: 1 week ago

Question

Differentiate Personnel Management and Human Resource Management

Answered: 1 week ago

Question

Describe the functions of Human resource management

Answered: 1 week ago