HTML5 Flappy Bird prototype using Phaser states, extended classes and Arcade physics

Ok, I am (quite) a bit in late to show you how to make an HTML5 Flappy Bird game because a lot of tutorial writer already published several “Create Flappy Bird with < language name >, anywway this is my take in the making of this game, basically for two reasons:

1) It’s the perfect game, in its simplicty, to merge some Phaser concepts such as states, extending classes and using Arcade physics.

2) It will be the starting point in the making of another endless runner tutorial.

So, let me clarify some concepts about this game:

* Like all endless runner games, the character you control does not actually move. It’s the whole environment which moves towards you.

* Obstacles, powerups and other interactive stuff appear from the right, move to the left and must be removed once they leave the stage.

* In this specific case, the game is built using Arcade physics, where the bird is the only actor to be affected by gravity, while pipes only move thanks to an horizontal force

* All pipes are children of a single group, and we are going to check for collisions between the bird and such group

* To restart the game, we simply call the game state, and Phaser will make the dirty job for us.

Before you dive into the really simple code, I suggest you to have a look to Phaser Tutorial: understanding Phaser states to see how Phaser manages states and Create an HTML5 game like “Drop Wizard” with Phaser – player fire, by extending sprite class to have the basics about extending classes.

This is the game you are about to create:

Use the mouse to flap.

And this is the source code, with space for customization as you can see from the comments on the first variables.

As said, this is only the first endless runner based on tapping, next week we’ll cover another one-button blockbuster, meanwhile download the source code.