What you'll build and what you need
You can recreate Flappy Bird in Scratch using sprites, simple physics, and event handlers — the same tools Scratch provides for any game. The finished project will have a bird that falls due to gravity, jumps when you press the spacebar, and collides with pipes that scroll across the screen. You do not need to install anything; Scratch runs in your web browser at scratch.mit.edu.
This project teaches you how games handle collision detection, continuous movement, and user input all at once. You will work with three main sprites: the bird, the pipes, and a score display. The whole game runs on a loop that checks for collisions and updates positions 30 times per second.
Key Takeaways
- The bird sprite needs a gravity script that makes it fall continuously, and a separate script that makes it jump when you press spacebar.
- Pipe sprites should clone themselves repeatedly and move left across the screen, then delete themselves when they leave the stage.
- Collision detection happens by checking if the bird sprite is touching a pipe or the ground, which ends the game.
- The score increases each time the bird passes through a gap between two pipes, which you track by checking the bird's x-position against the pipe's position.
Set up your sprites and stage
Start by opening Scratch and creating a new project. Delete the default cat sprite by right-clicking it and selecting Delete. You now have a blank stage to work with.
Create your bird sprite first. Click the paintbrush icon to draw a new sprite, or upload an image. A simple yellow circle with a small triangle for a beak works fine. Name this sprite "Bird". Next, create two pipe sprites — one for the top pipe and one for the bottom pipe. You can draw these as tall rectangles, or use the same sprite twice and flip it. Name them "TopPipe" and "BottomPipe". Finally, create a small sprite or use text to display the score; name it "Score".
Set your stage background to a light blue or sky color. This makes the game feel more like the original. You can also add a ground sprite at the bottom of the stage as a visual reference, though the actual collision will be handled by a script.
Program gravity and jumping for the bird
Click on the Bird sprite and open the Code tab. You need two separate scripts: one for gravity and one for jumping.
For gravity, create a script that starts when the green flag is clicked. Set a variable called "velocity" to 0. Then use a forever loop that adds a number like 0.5 to velocity every frame (this is your gravity constant). Change the bird's y-position by velocity each frame. This makes the bird accelerate downward smoothly. Add a condition: if the bird's y-position drops below a certain point (like -170, which is near the bottom), set the game over flag or broadcast a "game over" message.
For jumping, create a second script that waits for the spacebar to be pressed. When pressed, set velocity to -10 (a negative number makes the bird move up). This interrupts the falling motion and gives the bird an upward boost. You can adjust -10 to make the jump higher or lower.
Create pipes that move and clone
Click on the TopPipe sprite. Create a script that starts when the green flag is clicked. Set the pipe's x-position to 480 (off the right edge of the stage) and randomize its y-position between -80 and 0 so the gap is not always in the same place. Then use a forever loop that moves the pipe left by 5 pixels each frame.
Add a condition inside the loop: if the pipe's x-position is less than -240 (off the left edge), delete this clone. This prevents pipes from piling up in memory.
Now add a second script to TopPipe that creates new pipes. Use a forever loop that waits 2 seconds, then creates a clone of itself. This spacing controls how often pipes appear. Do the same for BottomPipe, but position it below the gap (for example, y-position between 80 and 160). Both pipes should move at the same speed so the gap stays aligned.
Detect collisions and end the game
Collision detection is how the game knows when the bird hits a pipe or the ground. Click on the Bird sprite and add a script inside your gravity loop that checks two conditions: "if touching TopPipe" or "if touching BottomPipe". If either is true, broadcast a "game over" message and stop the script.
You can also add a ground collision by checking if the bird's y-position is less than -170 (or whatever your ground level is). This prevents the bird from falling forever.
Create a separate script on the stage (not on a sprite) that listens for the "game over" broadcast. When it receives it, stop all scripts. This halts the bird, the pipes, and the score counter at once.
Track the score as the bird passes pipes
Create a variable called "Score" and set it to 0 when the green flag is clicked. Add a script to the Bird sprite that runs inside the gravity loop. Check if the bird's x-position just passed a pipe's x-position (for example, if the bird's x is greater than the pipe's x and the bird's x was less than the pipe's x in the previous frame). When this happens, increase the score by 1.
A simpler approach: check if the bird's x-position equals the pipe's x-position exactly. This is less reliable but easier to code. You can also add a small delay variable to prevent the score from increasing twice for the same pipe.
Display the score on the stage by creating a sprite or using the built-in score display. Set its text to "Score: " joined with the Score variable. Update this text every frame so it changes in real time.
Test and adjust your game
Click the green flag to start your game. The bird should fall, jump when you press spacebar, and collide with pipes. If the bird falls too fast or too slow, adjust the gravity constant (0.5) or the jump power (-10). If pipes move too quickly or too slowly, change the movement speed (5 pixels per frame).
If the bird gets stuck or pipes do not align, check that both TopPipe and BottomPipe are moving at the same speed and that their y-positions create a consistent gap. If the score does not increase, verify that your collision detection script is comparing the right positions.
Once the game feels right, you can add polish: sound effects when the bird jumps or collides, a restart button that resets all variables, or a high score tracker. These are optional but make the game feel more complete.
Frequently Asked Questions
Why does my bird fall through the pipes instead of colliding?
The "touching" block only detects collision if the sprites overlap in the same frame. If your bird moves too fast or your pipes move too fast, the bird can skip over a pipe without touching it. Slow down the movement speed or use a larger sprite size to make collision more reliable.
How do I make the game harder as the player progresses?
You can increase the pipe speed or decrease the gap size as the score goes up. Create a variable that tracks difficulty and changes the pipe movement speed based on the score. For example, if score is greater than 10, move pipes by 6 pixels instead of 5.
Can I add sound effects when the bird jumps?
Yes. Click on the Bird sprite, go to the Sounds tab, and upload or record a short sound. Then add a "play sound" block inside your jump script. Scratch has built-in sounds you can choose from without uploading anything.
What if the pipes are not spaced evenly?
Check that your clone creation script waits the same amount of time between clones (like 2 seconds). Also verify that both TopPipe and BottomPipe start at the same x-position and move at the same speed. If one pipe is faster, the gap will shift.
How do I add a restart button?
Create a sprite that looks like a button. Add a script that checks if the button is clicked. When clicked, set all variables back to their starting values (Score to 0, velocity to 0), move the bird back to the center, and broadcast a message to restart the pipes. Then click the green flag again or use a "start" block to resume the game.