How to Make a Flappy Bird Game on Scratch: Complete Tutorial

Reading Time: 13 mins

Introduction

When I first started teaching coding to kids, Flappy Bird was the game every student wanted to recreate. It’s easy to understand why – the game is simple yet challenging, addictive, and perfect for learning fundamental programming concepts. In my decade of experience as a coding instructor, I’ve found that creating a Flappy Bird game on Scratch is an ideal project for beginners who want to build something fun while developing their coding skills.

In this comprehensive guide, I’ll walk you through how to make a Flappy Bird game on Scratch from start to finish. By the end of this tutorial, you’ll have created your own version of this classic game that you can share with friends and the Scratch community. Let’s get started!

What is Flappy Bird?

Before diving into the coding process, let’s understand what makes Flappy Bird such an iconic game. Created by Vietnamese developer Dong Nguyen in 2013, Flappy Bird became a worldwide phenomenon for its deceptively simple yet frustratingly difficult gameplay.

The premise is straightforward: players control a bird that must fly between rows of green pipes without touching them. The bird automatically falls due to gravity, and players must tap (or click) to make the bird flap its wings and gain height. The game ends when the bird collides with a pipe or the ground.

What makes Flappy Bird perfect for recreating in Scratch is that it incorporates several fundamental programming concepts:

  • Gravity and physics
  • Collision detection
  • Scrolling backgrounds
  • Score tracking
  • Game states (start, play, game over)

I’ve found that students who complete a Flappy Bird project gain confidence in these concepts and are eager to apply them to more complex games.

Getting Started with Scratch

To begin creating our Flappy Bird game, you’ll need to set up your Scratch environment. Scratch is a block-based visual programming language developed by MIT that makes coding accessible to beginners.

You have two options for using Scratch:

  1. Online editor at scratch.mit.edu (requires a free account)
  2. Offline editor (can be downloaded from the Scratch website)

In my teaching experience, the online version is usually more convenient as it automatically saves your projects and allows for easy sharing. To get started:

  1. Create a Scratch account or log in if you already have one
  2. Click the “Create” button to start a new project
  3. Familiarize yourself with the Scratch interface:
    • Stage Area: Where your game will be displayed
    • Sprite Panel: Lists all the characters and objects in your game
    • Block Palette: Contains all the coding blocks categorized by function
    • Code Area: Where you’ll assemble your code blocks

If you’re completely new to Scratch, I recommend spending 15-20 minutes exploring the interface before continuing with this tutorial. Try dragging different blocks into the code area to see what they do.

Planning Your Flappy Bird Game

Before writing any code, it’s important to plan your game. In my years of teaching game development, I’ve found that spending time planning saves hours of debugging later.

For our Flappy Bird game, we’ll need the following elements:

  1. Sprites:
    • A bird character
    • Pipe
    • Background
    • Game over screen
    • Winning screen
  2. Variables:
    • Score
  3. Game Mechanics:

With this plan in mind, let’s start building our game step by step.

Step 1: Setting Up the Stage

Every good game starts with setting up the proper environment. For our Flappy Bird game, we need a suitable background for the stage.

  1. Click on the Stage in the bottom right corner of the screen
  2. Select the “Backdrops” tab
  3. Click “Paint” to create a new backdrop
  4. Create a simple sky background (light blue works well)
  5. Add a ground element at the bottom of the stage

Alternatively, you can use the “Choose a Backdrop” button to select a pre-made backdrop from the library. Sky backgrounds work best for this game.

Next, let’s create our game variables:

  1. Go to the “Variables” section in the block palette
  2. Click “Make a Variable”
  3. Create the following variables:
    • score – tracks the player’s current score
    • gravity – controls how fast the bird falls
    • speed – the bird’s current vertical speed
    • gameState – indicates if the game is playing or over

Make sure to set the variables as “For all sprites” since they’ll be used throughout the game.

In my experience, proper variable naming is crucial for keeping your code organized, especially as your game becomes more complex.

Step 2: Creating the Bird Character

[IMAGE 2: Side-by-side comparison showing the process of creating the bird sprite and its costumes]

Now, let’s create our main character – the bird:

  1. Click the “Choose a Sprite” button (cat icon)
  2. You have three options:
    • Search for a bird in the library
    • Paint your own bird
    • Upload a bird image

For beginners, I recommend choosing a bird from the library and modifying it. If you want to be authentic to the original Flappy Bird, you can paint a simple, small yellow bird.

To make the bird more dynamic, let’s create two costumes to simulate flapping wings:

  1. Select your bird sprite
  2. Go to the “Costumes” tab
  3. Duplicate the existing costume
  4. Modify the duplicate to show the wings in a different position
  5. Name the costumes “wings up” and “wings down”

Having two costumes will allow us to animate the bird’s wings when it flaps. In my classroom, students really enjoy this part of the process – seeing their static character come to life with simple animation.

Step 3: Programming the Bird’s Movement

Now for the fun part – making our bird move! Select your bird sprite and add the following code in the “Code” tab:

when green flag clicked
go to x: [-50] y: [0]
set [gravity v] to [0.5]
set [speed v] to [0]
set [score v] to [0]
set [gameState v] to [playing]

forever
    if <(gameState) = [playing]> then
        change y by (speed)
        change [speed v] by (gravity * -1)
        if <key [space v] pressed?> then
            set [speed v] to [8]
            switch costume to [wings up v]
            play sound [flap v]
        else
            switch costume to [wings down v]
        end
        if <touching [edge v]?> then
            set [gameState v] to [over]
            broadcast [game over v]
        end
    end
end

This code does several important things:

  1. Initializes the game variables
  2. Positions the bird on the left side of the screen
  3. Applies gravity to make the bird fall
  4. Makes the bird flap upward when the space key is pressed
  5. Changes the bird’s costume to simulate wing flapping
  6. Ends the game if the bird touches the edge of the screen

The gravity mechanic is particularly important in Flappy Bird. In my experience teaching this concept, I’ve found that students initially struggle with the idea of negative speed, so I make sure to explain how the speed variable represents the bird’s vertical velocity, which can be both positive (moving up) and negative (falling down).

Step 4: Creating and Coding the Pipes

[IMAGE 3: Screenshot showing the pipe sprites and their code blocks]

The next challenge is creating the pipes that our bird must navigate through:

  1. Click “Choose a Sprite” and select “Paint” to create a new sprite
  2. Draw a tall green rectangle to represent a pipe
  3. Name this sprite “Pipe Top”
  4. Create another sprite called “Pipe Bottom” with a similar design

Now, let’s program the pipes to move across the screen:

For the “Pipe Top” sprite, add this code:

when green flag clicked
hide
set size to [80] %
forever
    if <(gameState) = [playing]> then
        create clone of [myself v]
        wait [1.5] seconds
    end
end

when I start as a clone
go to x: [240] y: (pick random [0] to [100])
show
forever
    if <(gameState) = [playing]> then
        change x by [-5]
    end
    if <(x position) < [-240]> then
        delete this clone
    end
end

For the “Pipe Bottom” sprite, use similar code but adjust the y-position to ensure there’s a gap between the pipes:

when green flag clicked
hide
set size to [80] %
forever
    if <(gameState) = [playing]> then
        wait [1.5] seconds
        create clone of [myself v]
    end
end

when I start as a clone
go to x: [240] y: (pick random [-170] to [-70])
show
forever
    if <(gameState) = [playing]> then
        change x by [-5]
    end
    if <(x position) < [-240]> then
        delete this clone
    end
end

This code creates clones of the pipes that move from right to left across the screen. The random y-position creates varying heights for the pipes, making the game more challenging.

I’ve found that adjusting the pipe speed and spawn rate is crucial for balancing the game’s difficulty. Too fast, and the game becomes impossibly hard; too slow, and it loses its challenge. The values I’ve provided create a moderate difficulty that works well for beginners.

Step 5: Adding Collision Detection

Now we need to program what happens when our bird hits a pipe. Add the following code to your bird sprite:

when green flag clicked
forever
    if <touching [Pipe Top v]?> or <touching [Pipe Bottom v]?> then
        set [gameState v] to [over]
        broadcast [game over v]
    end
end

This simple code checks if the bird is touching either pipe, and if so, ends the game by changing the game state and broadcasting a “game over” message.

Collision detection is often tricky for beginners to understand. I always explain to my students that this is essentially how the computer “knows” when objects interact with each other in the game world. It’s a fundamental concept that applies to virtually all types of games.

Step 6: Creating a Score System

[IMAGE 4: Screenshot showing the score display and the code that increments it]

Every game needs a way to track progress, and in Flappy Bird, the score increases every time the bird successfully passes through a set of pipes.

Let’s create a scoring system by adding this code to the “Pipe Top” sprite:

when I start as a clone
wait until <(x position) < ([-50])>
if <(gameState) = [playing]> then
    change [score v] by [1]
    play sound [point v]
end

This code waits until the pipe has moved past the bird’s x-position, then increases the score by 1 and plays a sound effect.

To display the score, add this code to the stage:

when green flag clicked
forever
    if <(gameState) = [playing]> then
        say (join [Score: ] (score))
    end
end

In my experience teaching game development, implementing a scoring system dramatically increases student engagement. There’s something deeply satisfying about seeing your score go up as you successfully navigate obstacles.

Step 7: Adding Sound Effects

Sound effects make games much more engaging. Let’s add the following sounds to our Flappy Bird game:

  1. Select your bird sprite
  2. Go to the “Sounds” tab
  3. Click “Choose a Sound” and add:
    • A “flap” sound for when the bird flaps its wings
    • A “hit” sound for when the bird collides with a pipe
    • A “point” sound for when the player scores a point

Make sure the sounds are short and appropriate for the action they represent. In Scratch’s sound library, “Bird” works well for flapping, “Pop” for scoring points, and “Bonk” for collisions.

Now, update your code to play these sounds at the appropriate times. For example, add this to your bird’s collision detection code:

when green flag clicked
forever
    if <touching [Pipe Top v]?> or <touching [Pipe Bottom v]?> then
        play sound [hit v]
        set [gameState v] to [over]
        broadcast [game over v]
    end
end

In my teaching experience, sound effects are one of the easiest ways to make a game feel more professional and engaging. They provide immediate feedback to the player and make the game world feel more alive.

Step 8: Creating a Game Over Screen

When the game ends, it’s important to provide clear feedback to the player and give them an option to restart. Let’s create a game over screen:

  1. Create a new sprite and name it “Game Over”
  2. Design a game over message with the paint editor
  3. Add a “Click to restart” instruction to the sprite

Now, add this code to the “Game Over” sprite:

when green flag clicked
hide

when I receive [game over v]
go to x: [0] y: [0]
show

when this sprite clicked
broadcast [restart v]
hide

And add this code to the bird sprite to handle the restart:

when I receive [restart v]
go to x: [-50] y: [0]
set [speed v] to [0]
set [score v] to [0]
set [gameState v] to [playing]

Also, add similar restart code to the pipe sprites to clear any existing clones when the game restarts.

A proper game over screen helps create a complete game loop, which is essential for a polished gaming experience. In my classes, I encourage students to customize their game over screens with personal touches like congratulatory messages or fun facts about their high scores.

Step 9: Polishing Your Game

[IMAGE 5: Before and after screenshots showing the game with visual enhancements]

Now that we have the core gameplay working, let’s add some polish to make our game more appealing:

  1. Add a scrolling background:
    • Create a sprite for the background (like clouds or buildings)
    • Program it to move slowly from right to left
    • When it reaches the left edge, wrap it around to the right
  2. Add particle effects:
    • Create small sprites that appear briefly when the bird flaps
    • This adds visual feedback and makes the game feel more dynamic
  3. Create a start screen:
    • Design a welcome screen with instructions
    • Only start the game when the player clicks or presses a key
  4. Add a high score system:
    • Create a variable to track the highest score achieved
    • Update it when the current score exceeds the high score

Here’s a simple example of code for a scrolling background:

when green flag clicked
go to x: [0] y: [0]
forever
    if <(gameState) = [playing]> then
        change x by [-2]
        if <(x position) < [-480]> then
            set x to [480]
        end
    end
end

These polish elements may seem small, but in my experience, they make a huge difference in how professional and complete your game feels. Students often get extremely excited when adding these finishing touches because they see their project transforming from a basic prototype to something that looks and feels like a “real” game.

Step 10: Testing and Debugging

Before sharing your game, it’s important to thoroughly test it to catch any bugs or issues. Here’s a testing checklist I’ve developed for my students:

  1. Start the game:
    • Does the bird appear in the correct position?
    • Do the variables reset properly?
  2. Bird movement:
    • Does the bird fall due to gravity?
    • Does clicking/pressing space make the bird flap upward?
    • Does the bird animation work correctly?
  3. Pipes:
    • Do pipes appear at regular intervals?
    • Do they move at a consistent speed?
    • Is the gap between pipes passable?
  4. Collision detection:
    • Does the game end when the bird hits a pipe?
    • Does the game end when the bird hits the ground?
  5. Scoring:
    • Does the score increase when passing through pipes?
    • Is the score displayed correctly?
  6. Game over:
    • Does the game over screen appear?
    • Does clicking restart the game properly?

When you find issues, fix them one at a time and test again. Debugging is an essential skill for any programmer, and creating games is an excellent way to develop this skill.

Common Issues and Troubleshooting

In my years of teaching Scratch programming, I’ve encountered several common issues with Flappy Bird games. Here are some troubleshooting tips:

Issue 1: The bird moves too fast or too slow

  • Adjust the gravity and flap speed variables
  • Try smaller values for more precise control

Issue 2: Pipes are too difficult to navigate

  • Increase the gap between top and bottom pipes
  • Slow down the pipe movement speed
  • Make pipes appear less frequently

Issue 3: Score doesn’t increase properly

  • Check that the scoring code is in the correct sprite
  • Ensure the bird’s x-position is properly compared to the pipe’s position

Issue 4: Game doesn’t restart correctly

  • Ensure all sprites receive the restart broadcast
  • Check that all variables are reset properly
  • Make sure all clones are deleted when restarting

Issue 5: Collision detection seems inaccurate

  • Use the “ghost” effect to see the exact boundaries of your sprites
  • Adjust the size of the sprites for better collision detection
  • Consider using the “color touching color” block for more precise collisions

Remember, troubleshooting is an integral part of the programming process. In my classroom, I encourage students to see bugs not as failures but as puzzles to be solved.

Advanced Features to Add

Once you’ve created a basic Flappy Bird game, you might want to add some advanced features to make it more unique and engaging:

  1. Difficulty progression: Make the game gradually harder by:
    • Increasing pipe speed over time
    • Narrowing the gap between pipes
    • Making gravity stronger
  2. Power-ups: Create special items that give the player advantages like:
    • Temporary invincibility
    • Slower pipe movement
    • Wider gaps between pipes
  3. Different characters: Allow players to select different birds with unique abilities or appearances
  4. Day/night cycle: Change the background and lighting as the game progresses
  5. Medals or achievements: Award special recognition for reaching score milestones

In my experience teaching game development, these advanced features are where students really get to express their creativity and make the game their own. I’ve seen incredible variations of Flappy Bird, from space-themed versions to underwater adventures, all built on the same fundamental mechanics we’ve covered in this tutorial.

Conclusion

Congratulations! You’ve learned how to make a Flappy Bird game on Scratch. We’ve covered everything from setting up the basic game environment to adding advanced features and polishing touches.

Creating a Flappy Bird game is an excellent way to learn fundamental programming concepts like conditionals, loops, variables, and collision detection. These skills form the foundation for more complex game development projects.

I encourage you to experiment with your own unique ideas and themes. The most successful games are those that bring something new to the table while building on established mechanics. Share your creation with the Scratch community, get feedback, and continue to refine your game.

Remember, game development is an iterative process. Don’t be discouraged if your first attempt isn’t perfect – each version you create will be better than the last. As I tell my students, the most important thing is to have fun with the process and learn along the way.

Happy coding, and I can’t wait to see what amazing games you create!

Want to learn more about Scratch coding? Check out our other tutorials:

Tags

Share

Poornima Sasidharan

An accomplished Academic Director, seasoned Content Specialist, and passionate STEM enthusiast, I specialize in creating engaging and impactful educational content. With a focus on fostering dynamic learning environments, I cater to both students and educators. My teaching philosophy is grounded in a deep understanding of child psychology, allowing me to craft instructional strategies that align with the latest pedagogical trends.

Related posts