Introduction to Programming

Week 2: Crashy Bird - Advance

This is a simple version of the Flappy Bird game for micro:bit. The objective is to direct a flying bird, which is moving continuously to the right, between sets of obstacles. If the player touches an obstacle, they lose. The purpose of this tutorial is to teach the basics of game sprites, arrays, and loops.

ReminderOpen the Microbit editor

You will need to visit this website to the work: Microbit Makecode

Once you are there, click on New Project.

You have done this already many times !!

FundamentalStep 1: Add the Bird to the Game

FundamentalStep 2: Make the Bird fly

Before creating the code for the game actions, let's first add some controls so that we can move around. We'll control the bird by pressing the A button to go up or the B button to go down.

FundamentalStep 3: Generating obstacles

This is where things will start to get interesting. We're going to randomly generate obstacles. We'll keep all obstacles inside the array. All obstacles will have a single hole for the bird to fly through.

First, create an array of obstacles which will hold all of the obstacle sprites.

Now with every micro:bit restart you should see different auto-generated vertical obstacles.

Before continuing, make sure that obstacles are generated randomly and that the bird is moving up and down.

FundamentalStep 4: Make obstacles move

Obstacles should move towards left every second.

FundamentalStep 5: Make obstacles disappear

Make obstacles disappear after reaching leftmost corner. Iterate over all obstacles, delete the obstacle sprites where the X coordinate equals 0, and remove them from the obstacles array.

FundamentalStep 6: Generate more obstacles

FundamentalStep 7: Game Over

Right now nothing happens when the bird is hit by obstacle. Fix this by iterating over the obstacles array and checking if any obstacle sprite coordinate equals the bird coordinate.

ExampleFinal Code


Here are some additional features you can add to the game:

  • Count and show the Crashy Bird game score.

  • Make the obstacles move faster every time an obstacle is passed.

HomepageHomepagePrintPrintCreated with Scenari (new window)