Game tutorial · Flappy-style

How to make a flappy-style game in Scratch (step by step, with an AI helper)

In a flappy-style game the player taps to flap and must fly through gaps between pipes that keep coming. It is one of the best first Scratch games because it teaches three big ideas in one small project: gravity with a speed variable, clones for endless obstacles and a score that only counts once per pipe. This guide builds the whole game with real blocks, and shows where Bee, the AI buddy in Enimist's Maker Studio, can help.

Make the hero and the pipe

You need two sprites. The hero can be any small flying character – a bird, a bee, a paper plane. Keep it about 40 pixels wide.

The pipe is one sprite whose single costume holds BOTH pipes: a tall rectangle at the top, a gap of about 150 pixels, and a tall rectangle at the bottom. Make the costume around 700 pixels tall so that, when you move it up or down, the pipes always reach the edges of the stage. Moving one costume up and down is how the gap changes position.

Bee drawing a costume and a backdrop from a description (Vietnamese interface shown)
Bee drawing a costume and a backdrop from a description (Vietnamese interface shown)

Tip: Use the “Draw for me” chip in the Maker Studio's Bee panel for the hero (“a round yellow bird with big eyes”) and the backdrop. The pipe is easier to draw yourself with two rectangles.

Gravity and flapping

Make a variable “y speed”. Every frame gravity lowers the speed a little, and the hero moves by the speed – so it falls faster and faster. A flap simply sets the speed to a positive number, which throws the hero upward before gravity pulls it back.

Use a separate “when space key pressed” script for the flap. That way a flap happens once per key press instead of every frame while the key is held.

Blocks
when green flag clicked
go to x: (-120) y: (0)
set [y speed] to (0)
set [score] to (0)
forever
  change [y speed] by (-0.6)
  change y by (y speed)

when [space] key pressed
set [y speed] to (7)
start sound (Pop)

Endless pipes with clones

The original pipe sprite never plays – it hides and becomes a pipe factory. Every 1.5 seconds it creates a clone of itself.

Each clone starts on the right edge at a random height, shows itself and slides left by 4 steps at a time. After 125 moves (500 pixels) it has crossed the stage, so it deletes itself. Counting moves is safer than waiting for an x position, because Scratch keeps sprites partly on stage and a wide pipe might never reach the number you wait for.

Blocks
when green flag clicked
hide
forever
  create clone of (myself)
  wait (1.5) seconds

when I start as a clone
go to x: (260) y: (pick random (-80) to (80))
set [passed] to (0)
show
repeat (125)
  change x by (-4)
delete this clone

Score one point per pipe

A point should be added exactly once, when a pipe moves past the hero. Give the pipe sprite a variable “passed” (For this sprite only – every clone gets its own copy). Inside the clone's repeat loop, check: if this pipe is now left of the hero and has not been counted yet, change score by 1 and set passed to 1.

The hero sits at x = −120, so “left of the hero” means x position < −120. Show the score variable on stage so players can see it climb.

Blocks
if <<(x position) < (-120)> and <(passed) = (0)>> then
  change [score] by (1)
  set [passed] to (1)

Game over

Back in the hero's forever loop, check for crashes: touching the pipe, or falling below the bottom of the stage. When that happens, say “Game over!” for a moment and stop everything.

Want a restart without clicking the green flag? Replace stop all with a broadcast called “game over”, show a “Play again” button sprite, and reset score and position when it is clicked.

Blocks
if <<touching (Pipe)?> or <(y position) < (-170)>> then
  say (Game over!) for (1) seconds
  stop [all]

Make it feel good

Game feel is all in the numbers. Gravity −0.6 and flap 7 is gentle; try −0.8 and 8 for a snappier game. A wait of 1.5 seconds between pipes gives beginners time; 1.2 is harder. Point the hero in the direction of its speed (point in direction 90 − y speed × 3) so it tilts up when flapping and nose-dives when falling.

Add a sound for each point and a different one for the crash. In the Maker Studio, the “Make a sound” chip asks Bee for an effect such as “a happy ding for each point”.

Bee making a sound effect, with Stop and Open the Sounds tab buttons (Vietnamese interface shown)
Bee making a sound effect, with Stop and Open the Sounds tab buttons (Vietnamese interface shown)

Stuck? How the AI buddy can help

Bee can see your project, so ask exactly what is wrong: “My score goes up by 30 for every pipe – why?” (Answer: the passed check is missing.) Bee explains and points to the block instead of writing the game for you.

Want Bee to build it? Type what you want – “make the pipes come faster as my score goes up” – and Bee reads your project, prepares the change as a draft card (“Bee will: change 2 block(s)”) and waits. Tap Apply to put it in your project, or Discard; after applying, Undo puts everything back. Then tap “Done” to see how much of the game you made yourself.

Bee answering a question with a picture of the blocks (Vietnamese interface shown)
Bee answering a question with a picture of the blocks (Vietnamese interface shown)

Scratch is a project of the Scratch Foundation, in collaboration with the Lifelong Kindergarten Group at the MIT Media Lab. Enimist Studio is not affiliated with Scratch or the Scratch Foundation.

Ready to make a first game?

Open the Maker Studio on a computer – Bee will be there from the very first block.

More guides