Making a Pong Game in Scratch
A step-by-step middle-school lesson on building Pong in Scratch: a bouncing ball, a paddle you control with the mouse, bouncing off walls and the paddle, a score, and a game over. With a worked project and quiz.
Key takeaways
- Pong is built from a moving ball, a player-controlled paddle, and bounces
- A ball moves by repeatedly using 'move' and 'if on edge, bounce'
- The ball bounces off the paddle by flipping its direction when they touch
- A score variable counts each successful hit, and missing the ball ends the game
What is Pong?
Pong is one of the oldest video games ever made, and it is the perfect first "real" game to build in Scratch. The idea is simple: a ball bounces around the stage, and you slide a paddle to keep hitting it back. Miss the ball and the game is over. Building Pong teaches you three skills you will use in almost every game: making something move on its own, bouncing off surfaces, and following the mouse.
This lesson builds the classic one-paddle version, where the ball bounces off three walls and you defend the fourth. If Scratch is new to you, start with getting started with Scratch. Because the ball travels at angles across the stage, it helps to understand the grid first โ see coordinates and movement in Scratch.
The big idea: a ball that moves and bounces
A real ball does not need you to push it each moment โ it keeps going until something stops it. In Scratch we copy that with a forever loop. Inside the loop the ball does just two things: it moves a few steps in whatever direction it is pointing, and it bounces if it hits the edge of the stage.
The clever part of Pong is the direction the ball points. Direction in Scratch is an angle: 90 means right, -90 (or 270) means left, 0 means straight up, and 180 means straight down. Numbers in between, like 45, send the ball diagonally. Bouncing is really just changing that angle so the ball heads the other way.
Step 1: Add the ball and the paddle
- Delete the cat (right-click, delete).
- Click Choose a Sprite and add the Ball sprite. Shrink it a little if it looks too big.
- Add a second sprite for the paddle. The Paddle sprite exists in the library, or draw a long thin rectangle yourself in a bright colour.
- Drag the paddle to the bottom of the stage and the ball to the middle.
We will defend the bottom wall with our paddle, so the ball bounces off the left, right and top walls.
Step 2: Make the ball move and bounce off the walls
Click the ball sprite and build this script:
when green flag clicked
go to x: 0 y: 0
point in direction (45)
forever
move 8 steps
if on edge, bounce
Click the green flag. The ball shoots off at 45 degrees and bounces around the stage forever. The block if on edge, bounce does all the wall work for you: whenever the ball reaches any stage edge, it flips its direction so it heads back in. Right now it even bounces off the bottom, but we are about to change that so the bottom is the danger zone.
Step 3: Control the paddle with the mouse
Click the paddle sprite. We want it to slide left and right along the bottom, following your mouse. Build this:
when green flag clicked
set y to -150
forever
set x to (mouse x)
Now the paddle's up-and-down position is locked near the bottom (y is fixed at -150), and its left-right position copies mouse x every frame. Move your mouse and the paddle glides along with it. Tracking the mouse like this is far smoother than nudging with arrow keys.
Step 4: Bounce the ball off the paddle
Go back to the ball sprite. We need it to bounce up whenever it touches the paddle. Add a check inside the forever loop:
forever
move 8 steps
if on edge, bounce
if <touching [Paddle v]?> then
point in direction (180 - (direction))
move 12 steps
Read the new part carefully:
- touching Paddle? โ is the ball currently on the paddle?
- point in direction (180 - direction) โ this flips the ball's vertical travel. If it was heading down at 135 degrees, it now heads up; the maths mirrors the angle so it bounces realistically.
- move 12 steps pushes the ball clear of the paddle immediately, so it does not get stuck wobbling against it on the next frame.
Test it. The ball now bounces off your paddle and back up toward the top wall. You have a rally going!
Step 5: Add a score
A game needs a goal. Let's score a point every time the paddle saves the ball. Make a variable called score (Variables โ Make a Variable). Variables hold numbers that change as the game runs โ if they are new to you, see variables and score in Scratch.
In the ball's setup, reset the score, and add one point on each paddle hit:
when green flag clicked
set [score] to 0
go to x: 0 y: 0
point in direction (45)
forever
move 8 steps
if on edge, bounce
if <touching [Paddle v]?> then
change [score] by 1
point in direction (180 - (direction))
move 12 steps
The score now climbs every time you save the ball. It appears in the corner of the stage automatically.
Step 6: Game over when you miss
Right now the ball bounces off the bottom wall, so you can never lose. Let's fix that. Paint the bottom edge of the stage a special colour โ open the Stage backdrop and draw a thin red strip across the very bottom. Then, in the ball's loop, end the game if the ball touches red:
if <touching color [red]?> then
say [Game Over!] for 2 seconds
stop [all]
Now if the ball slips past your paddle and hits the red strip, the game stops. The top, left and right walls still bounce, but the bottom is yours to defend.
The full ball script
Putting it together, the ball has one script that does everything:
when green flag clicked
set [score] to 0
go to x: 0 y: 0
point in direction (45)
forever
move 8 steps
if on edge, bounce
if <touching [Paddle v]?> then
change [score] by 1
point in direction (180 - (direction))
move 12 steps
if <touching color [red]?> then
say [Game Over!] for 2 seconds
stop [all]
Common mistakes and how to fix them
- The ball passes through the paddle. Your paddle sprite name in the
touchingblock must match exactly. Pick it from the dropdown rather than typing it. - The ball sticks to the paddle and shakes. It is touching across several frames. The
move 12 stepsafter the bounce gives it space โ increase it if needed. - The game never ends. The red strip is too thin or a slightly different red. Make it a few pixels tall and use the dropper to match the colour in your
touching colorblock.
Reading your script step by step to find these problems is called debugging, and every game maker does it.
Try it: make it your own
You have a working Pong game. Now extend it:
- Speed up over time: each time the paddle hits the ball, also
change [speed] by 1and use that variable inmove (speed) stepsso rallies get harder. - Add lives: instead of instant game over, start with 3 lives, lose one on each miss, and reset the ball.
- Two players: add a second paddle at the top controlled by keys, and score against each other.
- Sound and colour: play a
popsound on each bounce and switch the ball's costume colour.
Bouncing and following the mouse are skills you will reach for again and again. Once Pong clicks, try a catch the falling objects game next. Have fun! ๐
Quick quiz
Test yourself and earn XP
How do you make the ball keep moving on its own?
A forever loop with 'move 10 steps' inside makes the ball travel continuously across the stage.
What does 'if on edge, bounce' do?
'if on edge, bounce' detects the stage edge and flips the sprite's direction so it bounces back into play, like a wall.
How does the ball bounce off the paddle?
When 'touching paddle?' is true, you reverse the ball's vertical direction so it travels back toward the player.
How do you control the paddle with the mouse?
In a forever loop you set the paddle's position to follow 'mouse x' (or 'mouse y'), so it tracks your mouse smoothly.
When should the game end in Pong?
Missing the ball means it reaches the wall behind the paddle. Detecting that with 'touching color' (or an edge) ends the game.
FAQ
This happens when the ball is still touching the paddle on the next frame, so it flips direction again and again. Fix it by moving the ball a few steps immediately after the bounce, or by only bouncing when the ball is moving toward the paddle, so it gets clear before the next check.
Set the ball's starting direction to something like 45 with 'point in direction (45)', and use 'turn' or 'point in direction' with varied angles when it bounces. A ball that only uses 0, 90, 180 and 270 degrees will never travel diagonally.
Keep exploring
More in Coding