Você está na página 1de 1

This extra bit of checking adds a fail-safe

feature to the code that prevents a ball from getting stuck should you
accidentally initialize it in a position where it's already colliding with an
edge. Without this check, a ball in collision with an edge may not be able to
move away from the edge before colliding with the edge again. This would
cause the ball's direction to reverse, then reverse again, on and on, forever

Chapter 1: Follow the Bouncing Ball , 3


The move ( ) method starts by adding the dx and dy delta values to the ball's
x and y position values to update the ball's position. This calculation may
move the ball out of bounds, so move ( ) then checks the new position
against the left and right bounds and then the top and bottom bounds.
You may notice that each collision test code case not only checks the ball's
position, but also checks to see if dx and dy are less than or greater than
zero, depending on the case.
.

Você também pode gostar