What You'll Build and Why It Works for Learning
Flappy Bird in Scratch teaches you the core mechanics that appear in almost every game: collision detection, score tracking, object movement, and user input. You will create a bird sprite that moves up when you click or press a key, pipes that scroll across the screen, and a system that ends the game when the bird hits an obstacle. The whole project takes two to four hours depending on your pace.
Scratch is free and runs in any web browser, so you need no special hardware beyond a computer with a keyboard and mouse. The visual block-based system means you do not write text code — you snap together logic blocks the way you would arrange puzzle pieces. This makes it possible to see exactly what each part of your game does.
This project is valuable because Flappy Bird's rules are straightforward enough to finish in one session, but complex enough that you will use real programming concepts: variables to track the score, loops to keep the game running, conditionals to check for collisions, and broadcasts to coordinate different parts of the game.
Key Takeaways
- You will need a Scratch account (free at scratch.mit.edu) and a web browser; no software installation is required.
- The bird sprite needs a gravity effect that pulls it downward constantly, with an upward jump triggered by a click or key press.
- Pipes are created as clones that move left across the screen and delete themselves when they leave the play area.
- Collision detection compares the bird's position to the pipe positions; when they overlap, the game stops and displays the final score.
- The score increases each time the bird successfully passes between two pipes without hitting them.
Setting Up Your Sprites and Stage
Start by going to scratch.mit.edu, signing in or creating a free account, and clicking "Create" to open a new project. You will see the default cat sprite on a white stage. Delete the cat by right-clicking it and selecting "Delete", then add three new sprites: one for the bird, one for the pipes, and one to manage the game logic.
For the bird, click "Choose a Sprite" and search for "bird". Pick any bird sprite you like — the exact appearance does not matter for the mechanics. For the pipes, search for "pipe" or use a straightforward green rectangle sprite. Create the pipe sprite first, then you will clone it to make multiple pipes appear. Add a third sprite called "Game Manager" by painting a new sprite; you can leave it blank or draw a straightforward shape, since this sprite will not appear on screen.
Set the stage background to something straightforward — light blue works well for sky. Click the stage thumbnail at the bottom left, then the "Backdrops" tab, and choose or paint a background. You now have all the pieces you need to start building the game logic.
Programming the Bird's Movement and Gravity
Click on the bird sprite to select it. In the Blocks panel on the left, you will see different categories: Motion, Looks, Sound, Events, Control, Sensing, Operators, and Variables. Start by creating a variable to track the bird's vertical speed. Click "Variables", then "Make a Variable", name it "bird_velocity", and click OK.
Now build the bird's main loop. Drag a "When Flag Clicked" block from Events into the code area. Attach a "Set bird_velocity to 0" block below it, then add a "Forever" loop. Inside the loop, add "Change bird_velocity by -0.5" (this is gravity pulling the bird down), then "Change y by bird_velocity" (this moves the bird). The bird will now fall continuously when you run the game.
Add the jump mechanic by creating a second script. Drag another "When Flag Clicked" block, then add a "Forever" loop. Inside, add "If key space pressed then set bird_velocity to 4". This makes the bird jump upward when you press the spacebar. You can change the 4 to a higher number if you want a bigger jump. Test by clicking the green flag — the bird should fall and jump when you press space.
Creating and Moving the Pipes
Click on the pipe sprite. Create two variables: "pipe_x" and "pipe_speed". Set pipe_speed to a number like 5 (this controls how fast pipes move left). Build a script that starts when the flag is clicked: set pipe_x to 240 (the right edge of the screen), then go to x position 240 and y position 0. Add a "Forever" loop that changes pipe_x by -5 each frame, moves the pipe to that x position, and deletes the clone when x is less than -240 (off the left side of the screen).
Now create a second script on the pipe sprite that generates new pipes at regular intervals. Start with "When Flag Clicked", then add a "Forever" loop containing "Wait 2 seconds", then "Create Clone of Myself". This makes a new pipe appear every two seconds. Adjust the wait time to make the game harder or easier.
The pipes need gaps so the bird can pass through. Modify the pipe sprite to be only the top or bottom half of a pipe, not a full vertical line. When you clone it, position some clones at the top of the screen and some at the bottom, leaving a gap in the middle. You can do this by adding a variable "pipe_height" and using a random number to vary where each pipe appears.
Detecting Collisions and Ending the Game
Click on the bird sprite. Add a new script that checks for collisions. Start with "When Flag Clicked", then add a "Forever" loop. Inside, add "If touching pipe then broadcast game_over". This sends a message to all sprites when the bird hits a pipe. You can also add "If y position is less than -180 then broadcast game_over" to end the game if the bird falls off the bottom of the screen.
Create a variable called "score" and set it to 0 at the start of the game. In the pipe sprite, add a check: "If x position equals 0 then change score by 1". This increases the score each time a pipe passes the center of the screen (you can adjust the x position to wherever you want to count the pass). Display the score on screen by clicking the checkmark next to the score variable in the Variables category.
Add a final script to the Game Manager sprite that listens for the game_over broadcast. When it receives it, add a "Stop All" block to freeze everything. You can also add a "Say" block to display "Game Over" or "Final Score: [score]" before stopping.
Testing and Adjusting Difficulty
Click the green flag to start your game. The bird should fall, jump when you press space, and pipes should scroll from right to left. Fly the bird through the gaps and watch the score increase. When you hit a pipe, the game should stop.
If the bird falls too fast or too slow, adjust the gravity value (the -0.5 in the gravity block) or the jump strength (the 4 in the jump block). If pipes move too fast or too slow, change the pipe_speed variable. If the gap between pipes is too tight or too wide, adjust the y positions where you place the pipe clones. If pipes appear too close together or too far apart, change the wait time in the pipe generation script.
Common issues: if the bird gets stuck at the top of the screen, lower the jump strength. If pipes do not delete properly, check that the x position threshold (-240) matches your screen size. If the score does not increase, verify that the pipe's x position check (equals 0) is actually where the bird is flying through.
Adding Polish and Next Steps
Once the basic game works, you can add sounds, different backgrounds, or a start screen. Click on the bird sprite, go to the Sounds tab, and add a sound for jumping and a sound for collision. In your code, add "Play sound" blocks at the right moments. You can also add a "Change Costume" block to make the bird flap its wings as it jumps.
For a start screen, create a new sprite or use the Game Manager sprite to display instructions before the game begins. Add a "Wait Until key space pressed" block before running the main game loop. This lets players read the controls before the game starts.
After you finish, you can share your project on Scratch by clicking "Share" at the top right. Other users can play it, remix it, and comment on it. Looking at how other people built their Flappy Bird clones teaches you different approaches to the same problem.
Frequently Asked Questions
Can I use the mouse to control the bird instead of the spacebar?
Yes. Replace the "If key space pressed" block with "If mouse down" from the Sensing category. The bird will jump whenever you click the mouse button. You can also use "If key up arrow pressed" or any other key you prefer.
How do I make the game harder as the player gets a higher score?
Add a block that increases pipe_speed or decreases the wait time between pipes based on the score. For example, "If score equals 10 then set pipe_speed to 6". You can add multiple checks at different score thresholds to gradually speed up the game.
Why do my pipes sometimes overlap or appear in weird positions?
This usually happens because the random y position for each pipe is not constrained properly. Make sure you are using a "Pick random" block with a minimum and maximum value that keeps pipes within the visible stage area, and that you are leaving a gap in the middle for the bird to fly through.
Can I add multiple lives instead of ending the game on the first collision?
Yes. Create a variable called "lives" and set it to 3 at the start. When the bird hits a pipe, decrease lives by 1 instead of broadcasting game_over when ready. Only broadcast game_over when lives equals 0. Reset the bird's position after each collision so the player can continue.
How do I save my project so I do not lose it?
Scratch automatically saves your project to your account as you work. Click "File" at the top left and select "Save Now" to manually save. You can also read your project as a file by clicking "File" then "read to your Computer" if you want a backup.