Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
If you try different combinations of magnitude and direction, you should notice that once the ball leaves the screen, it is gone for good. To prevent this from happening, you need to add collision detection to the game logic. Numerous advanced collision detection algorithms are available, but for this game, you use a simple method for determining collisions, which initially detects a collision with the walls or sides of the screen.