TODO1 - Use a single if statement to determine if the paddle and ball have collided.
"public void paddleBallCollisionCheck()"
   
  1. Find the TODO1.java starter file; this empty class also serves as a solution you can experiment and play with.
  2. Next, read all of the comments at the top of the file in the file header.
  3. Set your runner in Main.java to use TODO1.java and comment out any other setRunner calls. (see the stepwise approach for more details)
  4. Determine the single function you need to declare inside the empty class. It's described in the comments and also at the top of this webpage.
  5. Declare the function "public void paddleBallCollisionCheck(){}" and leave it empty and rerun the game - do you notice anything different?
  6. Inside your method, you must build one if statement that asks: "if the paddle and ball are colliding, then call some methods to reflect off the paddle and make a bounce sound."
  7. To build this if statement, you'll need to call one or more API functions to determine if a collision has occured; the API function you'll need are are described in the comments and also listed here for reference:

  8. Method Signature Description
    boolean ballCollidedWithPaddle() returns true if the ball and paddle images are overlapping or colliding
    void ballReflectOffPaddle() call this function to make the ball reflect off of the paddle after a collision
    void ballPlayBounceSound() call this function to make a bounce sound associated with the ball

  9. When you get the basics going, you might want to check out what you can do with the extended functions - see the comments in the code or the SpaceSmasher API Documentation for more on this.

  10. Extended Method Signature Description
    boolean ballCollidedWithPaddle(int whichBall, int whichPaddle) returns true if the ball specified by the integer index "whichBall" has overlapped with the paddle specified by the integer index "whichPaddle".
    void ballReflectOffPaddle(int whichBall, int whichPaddle) call this function to make the ball specified by the integer index "whichBall" reflect off of the paddle specified by the integer index "whichPaddle".