Learning Goals 3 min
By the end of this lesson you will have:
- Built a playable one-paddle Pong — a paddle that follows your mouse along the bottom, and a ball that bounces around the Stage and off the paddle.
- Used two velocity variables —
ball-vxandball-vy— to give the ball a direction and speed that can be reversed on bounce. (vx = "velocity in x", vy = "velocity in y".) - Detected a miss (the ball escapes past the paddle) with if <(y position) < (-170)> then, lost a life, and reset the ball — the same lives-and-game-over scaffold from cluster G.
Warm-Up — the new idea: velocity 5 min
Every catch-game you built in cluster G had falling things that moved downward — only. Down, down, down, off the bottom of the Stage. Once you knew an apple was falling, you knew everything about its motion.
Pong's ball is different. It can move in any direction. Up-right. Down-left. Straight across. And the direction can change mid-flight (bouncing). How do you store "moving up and to the right" in a single variable?
Reveal — you don't. You use two.
One variable holds how fast the ball is moving horizontally. Call it ball-vx. Positive means right, negative means left. The other holds how fast it's moving vertically. Call it ball-vy. Positive means up, negative means down. Together, these two numbers describe the ball's whole motion. Bouncing off a wall flips one of them. Bouncing off the top flips ball-vy. Bouncing off a side wall flips ball-vx. The ball doesn't need a "direction" — it just needs two velocity numbers.
This pair-of-numbers idea is called velocity, and it's how every game with bouncing or angled motion works. Once you get it, every old block makes new sense: change x by () is "apply horizontal velocity for one frame", change y by () is "apply vertical velocity for one frame".
The Game Plan 5 min
Three sprites and the Stage:
- Paddle — a short flat rectangle near the bottom of the Stage. Its y is pinned at
-150. Its x follows the mouse. - Ball — a small circle. Owns the two velocity variables and the bounce logic.
- Stage — owns
lives, the two backdrops (Play,Game Over), and the global setup.
The blocks we'll use, already familiar from earlier lessons:
set [ball-vx v] to (pick random (-5) to (5))
set [ball-vy v] to (-4)
change x by (ball-vx)
change y by (ball-vy)
set [ball-vx v] to ((0) - (ball-vx))
set [ball-vy v] to ((0) - (ball-vy))
The Build — nine steps to a working Pong 30 min
New Scratch project. Delete the cat. Let's build.
Step 1 — Backdrops
Click the Stage. Backdrops tab → add a plain dark backdrop (use the built-in Blue Sky 2 or Blue Sky or paint a black rectangle). Rename it Play. Duplicate it, add big white text "GAME OVER", rename Game Over.
Step 2 — Variables
Make three variables, all For all sprites: ball-vx, ball-vy, lives. Tick lives only — that's the watcher the player wants to see. Untick ball-vx and ball-vy; those are for the code, not the player.
Step 3 — Stage setup
On the Stage:
when flag clicked
switch backdrop to (Play v)
set [lives v] to (3)
Step 4 — The paddle
Paint a new sprite — a flat horizontal rectangle, about 80 pixels wide and 10 tall. Pick any colour. Name the sprite Paddle. On the paddle:
when flag clicked
go to x: (0) y: (-150)
forever
set x to (mouse x)
end
Step 5 — The ball sprite
Paint a new sprite — a small circle, about 20 pixels across, in a contrasting colour. Name it Ball. We'll add five scripts to it over the next four steps.
First, the launch script — every flag-click, the ball goes to the top-centre and picks a random starting velocity:
when flag clicked
go to x: (0) y: (150)
set [ball-vx v] to (pick random (-5) to (5))
set [ball-vy v] to (-4)
pick random (-5) to (5) is sometimes 0 — that's fine, it just falls straight down.Step 6 — The motion loop
Add a second script — the forever loop that applies the velocity:
when flag clicked
forever
change x by (ball-vx)
change y by (ball-vy)
end
Step 7 — Wall bounces
Add the wall-detection inside the same forever — three checks for the three walls we care about (top, left, right). Use the ball's coordinates, not touching [edge v] ?, because that block triggers on all four edges including the bottom (the bottom is where misses are).
when flag clicked
forever
change x by (ball-vx)
change y by (ball-vy)
if <(x position) > (230)> then
set [ball-vx v] to ((0) - (ball-vx))
end
if <(x position) < (-230)> then
set [ball-vx v] to ((0) - (ball-vx))
end
if <(y position) > (170)> then
set [ball-vy v] to ((0) - (ball-vy))
end
end
Step 8 — Paddle bounce
Add the paddle hit. When the ball touches the paddle, flip vy upward and nudge it out of the paddle so it doesn't get stuck inside.
if <touching [Paddle v] ?> then
set [ball-vy v] to ((0) - (ball-vy))
set y to (-135)
end
Step 9 — The miss
The last piece. If the ball escapes past the paddle (y < −170), lose a life and reset. If lives hit 0, broadcast game-over.
if <(y position) < (-170)> then
change [lives v] by (-1)
if <(lives) < (1)> then
broadcast (game over v)
stop [other scripts in sprite v]
hide
else
go to x: (0) y: (150)
set [ball-vx v] to (pick random (-5) to (5))
set [ball-vy v] to (-4)
end
end
On the Stage, add the game-over receiver:
when I receive (game over v)
switch backdrop to (Game Over v)
Click the flag. The ball drops from the top in a random angle. The paddle tracks your mouse. The ball bounces off the top and the side walls, and off the paddle when you catch it. Miss three times and the screen flips to GAME OVER. You just built Pong.
The full assembled ball script
when flag clicked
go to x: (0) y: (150)
set [ball-vx v] to (pick random (-5) to (5))
set [ball-vy v] to (-4)
forever
change x by (ball-vx)
change y by (ball-vy)
if <(x position) > (230)> then
set [ball-vx v] to ((0) - (ball-vx))
end
if <(x position) < (-230)> then
set [ball-vx v] to ((0) - (ball-vx))
end
if <(y position) > (170)> then
set [ball-vy v] to ((0) - (ball-vy))
end
if <touching [Paddle v] ?> then
set [ball-vy v] to ((0) - (ball-vy))
set y to (-135)
end
if <(y position) < (-170)> then
change [lives v] by (-1)
go to x: (0) y: (150)
set [ball-vx v] to (pick random (-5) to (5))
set [ball-vy v] to (-4)
end
end
Save as L02-42-Simple-Pong.sb3.
Three Extensions — pick at least one 10 min
Goal: Add a score that goes up every time the ball bounces off the paddle. Show the watcher on the Stage. See how high you can rally before you miss.
if <touching [Paddle v] ?> then
set [ball-vy v] to ((0) - (ball-vy))
set y to (-135)
change [score v] by (1)
end
score), one new line in the paddle-bounce block.Think: The paddle bounce is the natural "thing happened" moment in Pong. Just like catching an apple was the moment in cluster G. Every game has a beat — find it and reward it.
Goal: Speed up the ball every 5 bounces (cluster G's mod trick again). Increase both velocities by a small amount each time.
if <touching [Paddle v] ?> then
set [ball-vy v] to ((0) - (ball-vy))
set y to (-135)
change [score v] by (1)
if <((score) mod (5)) = (0)> then
set [ball-vy v] to ((ball-vy) * (1.1))
set [ball-vx v] to ((ball-vx) * (1.1))
end
end
Think: Multiplying a velocity by 1.1 preserves direction and just scales the speed. Adding instead of multiplying would mess up the direction. Multiplication is the right tool for "make this faster but don't change where it's going".
Goal: "Spin" — make the bounce angle depend on where the ball hits the paddle. Hit the left edge of the paddle → bounce left-and-up. Hit the right edge → bounce right-and-up. Hit dead-centre → straight up.
if <touching [Paddle v] ?> then
set [ball-vy v] to ((0) - (ball-vy))
set y to (-135)
change [score v] by (1)
set [ball-vx v] to (((x position) - (x position of [Paddle v])) / (10))
end
Think: This is exactly how the original 1972 Atari Pong worked. You've just rediscovered a 50-year-old game-design idea from first principles. The paddle is no longer just a wall — it's a tool the player can aim with.
Ship It — polish ideas 3 min
"Make it feel arcade"
Pong has been a polished game for over 50 years. Your version has the bones. Here's what to add, in order:
- Sound on every bounce. Add a play sound [Pop v] inside every bounce (wall, top, paddle). The original Pong's only sound was its bounce-blip, and that blip was the game.
- Different sound on miss. A low buzz on the miss block. The player learns the audio language without you teaching it.
- Paddle flash. On paddle hit, broadcast
flash. On the paddle, listen forflash→ change colour by 25, wait 0.05, clear graphic effects. Tiny visual feedback per hit. - Centre dotted line. Paint a vertical dashed line down the middle of the Play backdrop. Pure decoration. Makes it feel like Pong.
- Final score on GAME OVER. On the Stage, on game-over: say (join [Score: ] (score)) for (5) seconds.
Reveal — which is worth most?
Sound on bounce. By a mile. Audio feedback on every interaction is the cheapest fun-per-block in game design. Six blocks (three play sound additions) turn the game from "tech demo" into "I want one more round". Always add audio.
Recap 3 min
You built Pong. The big new idea: velocity. A moving thing has both a position (x, y) and a velocity (vx, vy). Each frame, position changes by velocity. Bouncing flips one component of velocity — vx for a side wall, vy for a top wall or the paddle. The pattern (one position, one velocity, frame-by-frame application) is how every physics-style game works — and your one-paddle Pong is a tiny but complete example. The rest of life is just more sprites with more velocities and more bounce rules.
- Velocity
- A sprite's speed-with-direction. Stored as two variables (
ball-vxfor horizontal,ball-vyfor vertical). Positive vx = right, positive vy = up. - vx and vy
- Short for "velocity in x" and "velocity in y". Names so common in game code that almost every game developer recognises them at a glance.
- Bounce (mirror)
- Flipping the sign of one velocity component. Top/bottom bounce → flip vy. Side bounce → flip vx. The other component is untouched.
- Stuck-in-the-wall bug
- The classic mistake: bouncing on touch, but the touch persists for several frames, so you bounce many times and the ball jitters. Fix by nudging the sprite out of the wall after the bounce, or by using coordinates instead of touching.
- Cluster H
- The Build-Reflect-Recap cluster. We leave catch games behind. Pong is the first build of the cluster.
Homework — remix your Pong 2 min
The Pong Remix. Take today's project and turn it into something distinctively yours. The core gameplay stays — paddle + ball + bounce + miss. The look, sound, and feel are up to you.
- Open today's
L02-42-Simple-Pong.sb3. Save asHW-L2-42-My-Pong.sb3. - Re-skin the ball. Replace the circle with a teh tarik glass, a sepak takraw ball, a durian, a roti canai — anything. Repaint the costume.
- Re-skin the paddle. A satay skewer? A racket? A rolling pin? Repaint the costume.
- Add at least one extension from the practice tasks above (score, speed-up, or spin).
- Add sound on at least the paddle bounce and the miss.
- Playtest for five rounds. Note your best score.
Bring back next class:
- The
.sb3. - A screenshot of your best score (paste it into the parent group chat — your remix counts as homework and a brag).
- Your answer to: "If you doubled both
ball-vxandball-vy, what would change about the ball's path? Speed, angle, both, or neither?"
Heads up for next class: SCR-L02-43 · Whack-a-Tikus stays in cluster H but switches genre — random spawn-and-hide instead of velocity. Tikus (mice) pop up at random spots on the Stage; the player clicks them before they vanish. You'll meet wait (pick random () to ()) seconds and the when this sprite clicked hat in a serious way.