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.
Reminder : Open 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 !!
Fundamental : Step 1: Add the Bird to the Game
Fundamental : Step 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.
Fundamental : Step 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.
Fundamental : Step 4: Make obstacles move
Obstacles should move towards left every second.
Fundamental : Step 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.
Fundamental : Step 6: Generate more obstacles
Fundamental : Step 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.
Example : Final Code
Warning : Extension
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.