Bird

by Soaring_Noob in Circuits > Microcontrollers

196 Views, 1 Favorites, 0 Comments

Bird

Flappy_Bird_icon.png

We are going to make a the Flappy bird game on microbit.

Supplies

MicroBit-klassenpakket.png

a Microbit + a usb cable to connect to ur computer.

and you will need the microbit editor online to make the code.

Add a Bird

Knipsel.PNG

First, add a sprite for the bird in the game and make it blink.

Make the Bird Fly

Knipsel.PNG

In advance you make the code for the game actions, firstly add controls so that it can move around.

Control the bird by pressing the A button to go up or the B button to go down.

Generating Obstacles

Knipsel.PNG

We're going to create barriers at random. All impediments will be kept within the array.

Every obstacle has a small hole through which the bird can fly. Make a "obstacle" line that will hold all of the obstacle sprites.

Make Obstacles Move

step 4.PNG

Using a "for element loop" (revisit through the obstacles array), access each obstacle and decrease the obstacle X coordinate by one. Rename the "value" block to "obstacle" by right-clicking it and moving it on top of "sprite" in the "change x" block.

Make Obstacles Dissappear

step 5.PNG

After reaching the leftmost corner, make obstacles disappear. Iterate via all obstacles and delete all sprites with its a X coordinate = 0 from the obstacles array.

Generate More Obstacles

step 6.PNG

Currently only one vertical hurdle is created by our code. To keep generating new obstacles, we must add code to the endless loop for obstacle generation.

As a result, there are numerous moving objects on the screen right now. Create certain spacing between barriers formed. For now, we'll construct a ticks variable to track how many iterations the endless loop has gone through, and only create obstacles if ticks is divisible by 3.

Game Over

step 7.PNG

When the bird is struck by an impediment, nothing happens. This can be fixed by iterating over the obstacles array and looking for any sprite coordinates that match the bird coordinate.

Knipsel.PNG

If you want you can add music to, to your game.

The Final Code

Knipsel.PNG

If you did everything right you should have this.

skrrt

A movie of how it works.