The Bouncing Ball

Space Invaders

How many characters are there? How many pixels are there? Which for() loop takes longer to run?

Space_Invaders

The Bouncing Ball

Now let's also make a conditional to prevent the ball from going off screen in the y direction. You'll notice that the ball goes in the same direction every time. Let's use the random() function to get the ball going in a different random direction each time.

Solution: