Following the bouncing ball
Now, it's time to create the heart of the program: the ball!
To get started, let's create a new sprite:
1. Start by importing a sprite from the library. There are numerous round ball-like
costumes to choose from. When you are happy with your costume, double-click on
it. Rename your new sprite to Ball .
2. Now, you will need to make two variables. Name them Left Score and Right
Score and set them to be used by all sprites.
3. When the green flag is clicked, set the size of the ball to 20 percent, and set both
left score and right score to 0 .
4. Move the ball to the center of the screen, and use a new block to point the ball in a
random direction. Random numbers are like picking a number out of a hat. You
don't know which one you will get ahead of time. Using a random block, we can
give Scratch two numbers, a small number and a large number, and it will pick a
random number in between these. By making the ball point in a random direction,
we add to the challenge and skill level of the game.
5. Now, onto the forever block. Each time it loops, we want to move the ball 5 steps.
We now have another new block, If on edge, bounce . This block tells the ball that
if it has touched the outer edges of the screen, it should bounce away from it.
6. We now have two if statements. These come into effect if the ball touches either
the left or the right paddle. If it touches either, we have the ball point in the oppos-
ite direction, and then pick a random direction to move in.