Advanced Games with Micro:Bit — Part 2

Wojciech Trocki
2 min readFeb 8, 2019

--

Part 1 of tutorial.

In second part of our tutorial we going to focus on adding opponents - the other cars that we need to avoid. Cars will appear first on the top of the screen and move towards player with constant speed that can be adjusted in the code.

Other cars driving towards player

Building main logic

We first need to start with adding a forever loop.
In the loop we going to check for situations where our car and others meet at the line position 5 which is the bottom of the micro:bit screen.

Our first check will check if emptySlot position is different that actual player position. If not this will mean that game is finished and player will see X on the screen.

We continue with resetting value of linePosition and drawing other cars in the new position.

Next we need to simulate our cars moving down towards player.
We can do that changing linePosition by one and drawing both player and other cars on micro:bit display

Try to change value of pause block. What you have noticed?

Entire loop should look like bellow

Forever loop displaying entire game logic

At this point our game is fully functional. Feel free to extend it by gradually increasing speed of the cars.

Have problems with your code?

See finished version of the game. Try to experiment with the code by changing other cars speed and reducing number of cars.

--

--