What You'll Build (and What You'll Learn)
Your finished game will have a bird that falls with gravity, flaps up when you press space, pipes that slide across the screen with random gaps, and a score that counts every pipe you pass. Hit a pipe or the ground — game over.
Flappy Bird is a genuinely useful project to build, not just a fun one, because it's the smallest game that still contains every core mechanic a bigger game needs: a physics-like variable that changes every frame, player input that fights against that physics, objects that spawn and clean themselves up, and a rule for what counts as "losing". Once these four ideas click, you can build platformers, shooters, and endless runners using the exact same building blocks.
- Gravity with a variable — the same trick real games use
- Clones — one pipe sprite becomes endless pipes
- Collision detection — touching blocks end the game
- Score keeping — variables that update live on screen
New to Scratch? Do Lesson 1 — Meet Scratch first (15 minutes). If you've never used variables, peek at Lesson 9 — the Catch Game where we explain them with pictures.
Step 1 — Set Up Your Sprites
Before any code goes down, the stage needs its actors. This step takes about five minutes but sets the foundation for everything after it — get the sprite names right now and every script later on is easier to read and debug.
Open a new project
Go to scratch.mit.edu → Create. Delete the cat (right-click → delete). Add a flying sprite — "Parrot" works great, or draw your own bird.
Add a pipe sprite
Click the paintbrush to draw a sprite: one long green rectangle at the top and one at the bottom, with a gap in the middle. Name it Pipe.
Pick a backdrop
"Blue Sky" from the backdrop library is the classic look.
Make two variables
In the Variables category, make velocity (how fast the bird falls or rises) and score.
Naming matters more than it seems. If you call your bird sprite "Sprite1" you'll spend the rest of the tutorial second-guessing which script belongs where — rename it Bird right away by clicking its thumbnail in the sprite panel and editing the name field.
Step 2 — Give the Bird Gravity
This is the heart of the game, and it's only a few blocks. On the Bird sprite:
when green flag clicked
go to x: -100 y: 0
set velocity to 0
forever
change velocity by -1 ← gravity pulls down a little more each frame
change y by velocity ← move by how fast we're falling
Press the green flag: your bird drops like a stone. That's gravity working! Every loop, velocity gets more negative, so the bird falls faster and faster — exactly like the gravity we build in Lesson 13.
The Numbers Behind the Fall (a Worked Example)
It helps to see exactly what the loop is doing frame by frame, rather than just taking it on faith. Say the bird just flapped, setting velocity to 10. Here's what happens over the next six frames, calculated directly from the two blocks in the script above:
| Frame | velocity (after -1) | y position (after +velocity) |
|---|---|---|
| 1 | 9 | 9 |
| 2 | 8 | 17 |
| 3 | 7 | 24 |
| 4 | 6 | 30 |
| 5 | 5 | 35 |
| 6 | 4 | 39 |
Notice the bird climbs less each frame, even though it's still moving up — that's why the arc curves instead of forming a sharp triangle. Eventually velocity crosses zero and turns negative, and the exact same two blocks now pull the bird back down. One tiny piece of arithmetic, repeated automatically, produces motion that looks like real physics.
Step 3 — Make It Flap
Add a second script to the Bird:
when space key pressed
set velocity to 10 ← a burst of upward speed
start sound [Chirp]
Setting velocity to 10 (instead of just moving up) means gravity immediately starts eating the boost — so the bird arcs beautifully instead of teleporting. Small numbers = heavy bird, big numbers = floaty bird. Try 8, 10 and 13 and pick your favourite!
Why Forever Loops Are the Heartbeat of Every Game
It's worth pausing here to understand why the gravity script works, because the same shape — a forever block running dozens of times a second — sits underneath practically every video game ever made, from Flappy Bird to the biggest console releases. Each pass through the loop is called a frame, or a "tick": the game checks input, updates positions, checks for collisions, and redraws the screen, then does it all again immediately.
Scratch runs its forever loops roughly 30 times a second by default. That's fast enough that a bird falling one pixel per tick looks like smooth motion to your eye — the same illusion that makes a flip-book or a film reel look alive.
Step 4 — Endless Pipes with Clones
You only need one Pipe sprite. Clones do the rest (this is the same trick from our Balloon Pop lesson). On the Pipe sprite:
when green flag clicked
hide
set score to 0
forever
create clone of [myself]
wait 2 seconds
when I start as a clone
go to x: 240 y: (pick random -60 to 60) ← random gap height
show
repeat until x position < -235
change x by -4 ← slide left
delete this clone
Every 2 seconds a new pipe is born on the right edge at a random height, slides across the stage, and deletes itself off the left edge. Endless pipes, three blocks of memory.
Clones vs. Making New Sprites
A common early mistake is duplicating the Pipe sprite by hand in the sprite panel to get more pipes. It works for exactly one screen, then falls apart. Here's why clones are the right tool for this job:
| Duplicate sprites | Clones | |
|---|---|---|
| How many you can make | A fixed number, set by hand | Unlimited, created while the game runs |
| Code you have to write once | Once per duplicate sprite | Once, ever — every clone reuses it |
| Memory when off-screen | Stays in memory even off-stage | Deletes itself and frees memory |
| Good for | A small, fixed cast of characters | Bullets, pipes, enemies, particles — anything repeating |
Step 5 — Game Over and Scoring
This is where the game gets rules. Right now the bird can fall forever and pipes can pass straight through it — nothing actually ends the game or rewards the player for surviving. Two small checks fix both problems at once. Back on the Bird sprite, add these checks inside the forever loop (after change y by velocity):
if touching [Pipe] ? then
broadcast [game over]
stop [all]
if y position < -170 then ← hit the ground
broadcast [game over]
stop [all]
For scoring, add to the Pipe clone script, just before delete this clone:
change score by 1
start sound [Coin]
Broadcasting a message like game over lets every sprite react independently — the Bird can stop moving, the Pipes can freeze in place, and a "Game Over" text sprite can appear, all triggered by one signal instead of you wiring separate checks into every single sprite.
If your bird dies instantly, your pipe costume probably fills the whole canvas — Scratch detects touching against the drawn pixels. Make sure the gap in your pipe drawing is really empty (transparent), not white.
Troubleshooting: Common Bugs and Fixes
Every Scratch builder hits the same handful of snags on this project. Here's the fast diagnosis for each one, before you spend twenty minutes staring at blocks that look correct.
| Symptom | Likely cause | Fix |
|---|---|---|
| Bird falls but never flaps | The flap script is on the wrong sprite, or the key isn't set to "space" | Check the flap script is on the Bird sprite and the hat block reads space |
| Bird dies the instant you press play | Pipe costume has no transparent gap | Redraw the gap with the eraser tool, not white paint |
| No pipes ever appear | The clone script never ran, or "when green flag clicked" is missing | Confirm the Pipe sprite has its own green-flag hat block |
| Score doesn't increase | The change score by 1 block sits outside the clone script | Move it inside when I start as a clone, before delete |
| Game restarts oddly on green flag | Old clones from the last run weren't cleared | Add delete this clone as a safeguard and avoid stray clone-creation loops |
| Bird flies off the top of the screen | Velocity keeps adding without a cap | Add an if velocity > 10 then set velocity to 10 check |
Step 6 — Make It Yours
The base game is complete and playable at this point — everything below is optional polish. Pick two or three, not all six at once, or you'll lose the plot debugging six new features simultaneously.
speed variable instead of -4 and change it by -0.2 every 10 points, so the game gets harder the longer you survive.score > high score, so players have something to beat next run.FAQ
Do I need to install anything to follow this tutorial?
No. Scratch runs entirely in your browser at scratch.mit.edu — no downloads, no account required to build and test the game, though you'll want a free account to save your project.
My pipes overlap the bird's starting position — what's wrong?
Check the pipe's starting x position matches the stage width you're using (240 for the default 480-wide stage) and that the bird's starting x (-100 in this tutorial) leaves enough runway before the first pipe arrives.
Can I make the bird a different character, like a rocket or a fish?
Yes — the gravity and flap scripts don't care what the sprite looks like. Swap the costume for any sprite from the library or draw your own, and consider renaming the pipes to match your new theme (asteroids for a rocket, for example).
Why does my score reset to a huge number instead of 0?
This usually means set score to 0 is missing from the green-flag script, so the variable keeps whatever value it held from a previous test run. Add it back at the very start of the Pipe sprite's script.
How do I make the game harder without it feeling unfair?
Increase difficulty gradually rather than all at once — shrink the pipe gap or speed up the pipes by a small amount every few points, instead of a single jump in difficulty right after the game starts. Players notice a game that "cheats" far more than one that ramps up smoothly.
Before You Call It Done — Test These
It's tempting to stop as soon as the game runs once without crashing. A quick pass through this checklist catches the bugs that only show up after a few minutes of real play, not the first ten seconds.
- Play for at least 60 seconds straight — some bugs only appear once dozens of clones exist
- Press space rapidly several times in a row — check the bird doesn't fly off-screen
- Let the bird fall without pressing anything — confirm it dies at the ground, not before
- Check the score increases exactly once per pipe, not twice or zero times
- Click the green flag again after a game over — confirm it resets cleanly
- Ask a friend or sibling who's never seen the code to play it blind — real playtesting beats your own biased runs
· · ·
You Just Built a Real Game
Gravity, clones, collisions, score — these four patterns power thousands of games. Change the bird to a rocket and pipes to asteroids and you've made a totally new game with the same code. That's the real skill you've practiced here: recognising that "different game" often just means "different costume on the same logic".
The Essential Points
- Gravity = a velocity variable that shrinks every frame and moves the sprite
- Flapping = setting velocity to a positive burst, then letting gravity win
- One pipe sprite + clones = infinite obstacles with random gaps, and clones clean up after themselves
- Touching blocks + broadcast = clean game-over logic
- Every game is built from the same loop: check input, update, check collisions, redraw, repeat
- Ready for more? Build the Space Shooter next — it levels up every trick you used here