Explanation
The code in Listing 6:
- Saves the current position coordinates for the ball, and
- Updates the direction in which the ball will move if it has collided
with a wall, or
- Computes the position coordinates for the next location of the ball if
it hasn't collided with a wall.