Flappy Bird is a super simple, yet addictive game where you control a little bird trying to fly through gaps in green pipes without hitting them. The game uses just one control: you tap the screen to keep the bird in the air. Timing is everything, as each tap makes the bird flap and go up slightly. The goal? Get as far as possible without crashing! It sounds easy, but the challenge lies in perfecting your timing. It’s a game of patience, skill, and just a bit of luck.
Let's make Flappy Bird in Scratch this time!
Pipe
First, let’s start by creating the pipe sprite!
Costume
Delete costume1. Sorry cat! Maybe later!
Select all the parts of the cat and delete them to quickly get a blank costume.
Top
Click the rectangle tool and draw a square that’s 100 by 50.
Change color settings.
- Color 40
- Saturation 100
- Brightness 40
Click the gradient button, choose the right color, and adjust the color settings.
- Color 40
- Saturation 100
- Brightness 100
And also set the outline.
- Thickness 6
- Color 40
- Saturation 100
- Brightness 30
Looks like this! Beautiful!
Body
Draw the long rectangle below and click the Backward button.
Draw it so it goes beyond the edge of the screen.
Neck
Draw a flat rectangle between the top and body of the pipe.
- Color 40
- Saturation 100
- Brightness 30
Highlight
Add a highlight.
- Color 40
- Saturation 50
- Brightness 89
Add another highligh to the pipe's body.
Make the top a little.
Name
Name this costume pipe.
Corner
Select the Reshape tool and add two points near the top-left corner.
Then select only the left-top corner and click the Delete button.
Does the corner look rounded now?
Let’s round the corner on the right side the same way.
Select all parts of the pipe, and click the Group button.
Copy, paste, and click the 'Flip Vertical' button.
Move and adjust it to make it symmetrical top to bottom.
Check the preview screen as well. If the X and Y coordinates are set to zero, it should look like this.
Coding
Alright, let's move on to coding the pipe!
Place the green flag block and hide.
Place the forever block.
Create clone of myself inside.
Wait 3 seconds.
When I start as a clone
Let's set up the cloning process.
Make the Y value randomly choose between -70 and 70.
And show.
Preview
Let’s preview it! Each time you press the green flag, a set of pipes appears with a random Y position.
Place 'repeat until' block.
Insert the expression ' x position < -240' into the condition.
Change x by -3 inside.
Finally delete this clone.
Preview
Woo-hoo! Now the pipes scroll across the screen just like in Flappy Bird!
Cat Flying
Alright, let's make a new sprite!
Type 'cat' and choose 'Cat Flying' from the Scratch library.
Coding
When the green flag clicked, set x to -80 and y to 0.
Point in direction 90.
Set size to 50%.
Go to front layer.
And show.
Preview
Now the cat seems to be flying between the pipes! Cool!
Place a forever block.
Gravity
Make a new block definition named Gravity.
Use this inside the loop.
Variable 'SPEED Y'
Make a new variable named SPEED Y.
In the Gravity, change y by 'SPEED Y'.
Change SPEED Y by -0.5.
Jump
Add another definition named Jump.
Place this after the Gravity code inside the loop.
In the Jump, place the 'if' block first.
Insert 'key space pressed?' into the condition.
Set SPEED Y to 4 inside.
Preview
Good enough! Now the cat’s movement is much closer to Flappy Bird.
Game Start
With this feature added, pressing the green flag makes the cat start falling immediately, creating a rushed start. Let’s make a few tweaks to improve this!
Place 'wait until' block with 'key space pressed?' in the condition.
This way, the game won’t start until the space key is pressed.
Message 'Game Start'
Create a new message named 'Game Start'.
Place this message following the 'wait until' block.
Pipe
Click on the pipe sprite. Oops, I forgot to name the last sprite! Let’s name it "Pipe" at this point.
Place the 'when I receive Game Start' block near the sequence that starts with the green flag.
Move almost all the blocks that follow the green flag block together.
Improvement
Let’s keep improving to make it even better!
Angle
Open the Cat Flying sprite.
Make a new block definition named 'Angle'.
Place this block in the forever loop block in the sequence that starts with the green flag.
Place 'if - else -' block first.
Insert the expression 'SPEED Y > -5' into the condition.
If the condition is true, point in direction 60; otherwise, point in direction 120.
Preview
Nice! The character’s heading up when it rises and down when it falls! Cool!
Game Over
Use this block in the main loop.
Place 'if' block with 'or' condition block.
Insert 'touching Pipe?' on the left and 'touching edge?' on the right.
Message 'Game Over'
Broadcast Game Over inside the block.
Variable 'ALIVE'
Create a new variable named ALIVE.
When I receive the message 'Game Over,' set ALIVE to 0.
Also, in the main sequence that starts with the green flag, set ALIVE to 1 before the forever loop.
Add 'if' block in the Jump.
Insert the expression 'ALIVE = 1' into the condition.
Add the same 'if' block to the Game Over.
Open Pipe.
When I receive 'Game Over,' stop other scripts in the sprite. This makes the pipes stop scrolling when the game is over.
SCORE
From here, let's set up a scoring system that adds points every time the cat passes a pipe!
Variable 'SCORE'
Set SCORE to 0 first.
Add another 'when I start as a clone' block.
Wait until 'x position < -140,' which means the cat has passed the pipes.
Add 1 to the SCORE.
Preview
Wow! You can see the score go up each time the cat passes pipes! Fantastic!
Background
Pick any background you like from the Scratch library, and our Flappy Bird game is complete! Woohoo!