Step 9: Ball Edge Collision Code 1

Goal:


Now that our ball and our paddle can collide with each other, we need to tell the ball what happens when it touched the edge of the screen.

If it ever touches to bottom of the screen we need to lose the game, so let’s start with that code.

Steps:

  1. From Ball1, place a EdgeReached block.
  2. From Control, place an IF/THEN block.
  3. From Math, attach an =(equal) block to the IF portion of the IF/THEN block.
  4. From the EdgeReached block, hover over the orange edge circle, then grab the get edge block and place it in the left side of the =(equal) block.
  5. From Math, place a 0(zero) block in the right side of the =(equal) block and set it to -1.
  6. From Notifier, place a call Notifier.ShowMessageDialog block in the THEN portion of the IF/THEN block.
  7. From Variables, attach a get Points block to the message slot of the ShowMessageDialog block.
  8. From Text, attach an empty text box block into the title slot of the ShowMessageDialog block, and set the text to “Game Over!”.
  9. From Text, attach an empty text box block into the buttonText slot of the ShowMessageDialog block, and set the text to “Play Again”.

Code: