Pong
Watch the movie
Step 1. Create 3 sprites
Step 2. Create the end script
Step 3. Create the paddle script
Step 4. Create the ball script
Watch the movie
Watch the movie below to see the simple game of pong that we’ll create.
Step 1. Create 3 sprites
You’ll need to create 3 sprites like the ones below. Be sure to give them the same names that they have in the picture.
Step 2. Create the end script
Our end sprite appears as a platform at the bottom of the screen. You’ll need the commands below to position the end sprite properly. Can you change the numbers appropriately and assemble the commands?
Step 3. Create the paddle script
Switch to the paddle script tab.
The paddle moves only to the left or right (not up or down), following the mouse pointer as it moves from one side to another.
There’s a trick to this motion! The paddle follows the mouse x position. For example, suppose that the mouse moves towards the right edge of the screen and its mouse x position becomes 200. At that moment, we want the paddle x position also to be 200. Or if the mouse moves towards the left edge of the screen and its mouse x position becomes -125, then we want the paddle x position also to be -125. On the paddle script, we can use the following commands to create this effect. Can you find these commands in Scratch?
How would you assemble the following commands, changing the numbers where necessary, to make the paddle move correctly?
Step 4. Create the ball script
Switch to the ball script tab.
The ball starts its motion towards the top right of the screen and then bounces around the screen continuously, changing direction when it touches the walls or the paddle.
To begin, let’s make the ball move continuously, bouncing off the walls. You can use the commands below. Can you assemble them in the correct order and with the correct values? (Hint: You can change the direction command by pulling down its menu or by typing the desired direction using degrees into its white box.) How would you make the ball move faster or slower?
Now that the ball is bouncing around the screen properly, let’s make it bounce off the paddle as well.
To make the ball bounce off the paddle, let’s think about what happens when a real ball bounces. Let’s say that the ball is traveling at a direction of 120 degrees (towards the lower right). When this ball strikes a horizontal surface like the paddle, its new direction will be 60 degrees. Or if a ball is traveling at a direction of 150 degrees, then after striking a surface, its new direction will be 30 degrees. What’s the pattern? The new direction can always be calculated like this:
new direction = 180 – original direction
In Scratch, we can get this effect through the following commands:
And here are the 3 new commands, including the one above, that you should add to your ball script to make the ball bounce off the paddle. Can you figure out where to put them in your ball script?
Finally, if the fall touches the platform at the bottom of the screen, the game ends. Here are the 3 commands you’ll need to make the ball behave in this way. Can you figure out where to place them in the ball script?
. . .
Congratulations! Enjoy your game!







