Best Scratch Coding Projects for kids: Flappy Bird

Introduction:

In this lesson, we are going to be creating a simple flappy birdgame using Scratch. This is a great project for those who are looking for a funway to improve their knowledge of Scratch.

Table Of Content:

Who is this Project For?

This is a beginner-level project for those who are new to Scratch. Before beginning, you should already have some experience with creating costumes, variables, and if statements, and using operators. These will be the core concepts used and built upon in this project.

 

What Will We Learn?

This project focuses on using knowledge of Scratch components like if-statements and operators. By the end of the project, you will be able to use these concepts to create a simple game.

 

Features to Consider:

  • When the green flag is pressed a start button will appear.
  • When the player clicks on the start button the game will begin.
  • The player will press the spacebar to make the bird fly.
  • If the bird touches an obstacle or the ground, the game will end.

Main Steps:

This project has 4 main steps:

1.      Create the sprites and backdrop

2.      Code the start button

3.     Code the bird sprite

4.      Code the obstacles

 

Step 1: Create the sprites and backdrop

The first thing we’ll need to do is create all the sprites and the backdrop we need for the game. For the backdrop, we can create our own by drawing some grass and bushes against a blue sky. The backdrop will be the main backdrop for the game. Next, it’s time to make the start button. This will be a coloured rectangle that says “Start” on it. Once the button and backdrop are complete, they will look like this:

Scratch flappy bird 1

Now we need to draw the bird sprite (or choose one from the sprite library). To draw the bird, We will use circles for the body and eye, and ovals to make the beak and wings. Once the bird sprite’s costumes are complete it should look like this:

Scratch flappy bird 2
Hint: If we want the bird to be animated we will create multiple costumes where the wings are in slightly different positions.

Finally, we need to make the obstacle sprites. Start by creating two rectangles coming from the top and bottom of the screen. Make the ends a bit wider than the rest of the obstacle. Next, duplicate the


original costume, and change the heights of the obstacles. This will make the game harder by forcing the player to move the bird up and down while playing. Once complete, the obstacles will look like this:

Scratch flappy bird 3

 

Step 2: Code the start button

Once we've created our sprites, we can get on to creating the code to make the start button functional. Start by selecting a “when green flag clicked” block, and add a block to broadcast a new message called “reset” underneath. Next, select a “when I receive” block and select the reset message. When the sprite receives this message, we want it to go to (0, 0) and show itself so we will add those blocks underneath. Now we need to define what the sprite will do when it is clicked.

Bring out a “when sprite clicked block” to sense whether the button is clicked. Then, create a new message called “start” and make the button broadcast this message if it is clicked. Finally, hide the button after the start message is broadcasted. In the end, the code will be:

Scratch flappy bird 4

 

Step 3: Code the bird sprite

Next, we need to create the code for the bird sprite. Start by defining what happens when the sprite receives the reset message. Using a “when I receive” block, we need to select the reset message, and underneath, show the sprite and send it to (0, 0). Then, bring two “when I receive start” blocks into the workspace. Under the first one, create a new variable to act as the score and set it to zero. Next, set the bird’s costume to the first costume and show the sprite. Select a “wait one second” block and a forever loop and add them to the code as well. Inside the forever loop, we will set the bird sprite to the front layer to ensure that it is never covered up. Next, we will use an if statement to check if the sprite is touching the grass at the bottom of the backdrop. If so, the sprite should broadcast the reset message and wait, then stop all running code.

Hint: Use the touching colour sensing block to check if the sprite is touching a specific colour. You can use the eyedropper tool to easily select the exact colour of the grass.

Once this is done, the code will look like this:

Scratch flappy bird 5

Under the second start block, create a variable called “gravity” and set it to 0. Underneath, bring out a forever loop and insert an if-else statement inside. Inside the forever loop, change the y-coordinate by the gravity value. This will allow the bird to fall if the space bar is not pressed. Then, use the

if-else statement to check if the space key is pressed. If so, set gravity’s value to 4, otherwise the gravity will be changed by -0.4. Finally, we will need to create the bird’s flying animation. Do this by bringing out a “when space key pressed” block, and adding a repeat loop underneath to repeat the next code section twice. Then, add a block to wait 0.1 seconds, and change the costume to the second costume. Wait another 0.1 seconds before changing the costume back to the original costume. Once the code for this sprite is complete we will have:

Scratch flappy bird 6


Step 4: Code the obstacles

The last sprite we need to code is the obstacle sprite. Start by bringing out two “when I receive” blocks and selecting the start messages. Under the first one, create a variable called “speed” and set it to 8.

Hint: Setting the speed variable to a smaller number will make the game faster and larger numbers will slow it down.

Then, add a “wait one second” block and a forever loop. Inside the forever loop, create a clone of the obstacle sprite and wait for speed ÷ 2seconds. This will create clones of the obstacle sprite at regular intervals as the game goes on. Now we’ll move on to the second start block. Start by resetting the timer using the “reset timer” sensing block and waiting for one second. Then, use a forever loop. Inside, wait 2 seconds and set the speed to anew value. For this step, we will use the subtraction and division operator blocks to set the speed to 8-(speed÷10). Once these blocks have been completed the code will look like this:

Scratch flappy bird 7

Now, bring out two “when I start as clone” blocks. Under the first one, add a forever loop with an if statement inside. Use a sensing block to check if the obstacle sprite is touching the bird sprite. If so, broadcast the reset message and wait, then stop all running code. Underneath the second clone block, set the sprite’s location to (280, 5). Then, use an operator and a costume block to switch the sprite’s costume randomly, then show the sprite. This will result in obstacles of different heights.

Finally, make the sprite glide for a set amount of time to (-240, 5) and delete the clone. This will make the sprite move along the canvas and disappear once it is out of sight.

Hint: set the number of seconds to the value of speed to make the whole game run smoothly. When complete, the code will be:
Scratch flappy bird 8

Finally, select a “when I receive reset” block and a “when I start as clone” block from the menu. Under the reset block, add a hide block to hide the sprite. For the start as a clone block, use operator blocks to wait for speed ÷ 2 seconds before changing the score by 1. This will increase the player’s score as they pass through an obstacle. Once this step is finished, the code is complete and should look like this:

Scratch flappy bird 9

 

Project Complete!

And now we’re done! Feel free to test your game and see how it works. If you’re stuck or have any issues with your code, try reviewing it to see if you’ve made any mistakes, or check out the code shown above as a reference.

Keep Learning: Scratch Coding for Kids

Geekedu offers Scratch coding for kids that teaches beginners fundamentals in coding by making games. Outside of Scratch, we also teach coding courses for kids 8-18 in a variety of languages like Python, Java, C++, Animation and more.

Check out our online courses for kids, or contact our admissions team to learn which course is best for your student!

Geekedu is an expert in Coding and Math learning. Our goal is to inspire and empower youth to use their knowledge of technology to become the influencers, inventors and innovators of the future.

Sign up and get a 60-minute free assessment class

Book A FREE Trial