Game Microbit
60 mins
Teacher/Student led
115 points
What you need:
Chromebook/Laptop/PC
Microbit

Get ready for an exciting coding adventure! In this lesson, you'll create a countdown timer, define key game elements like Bullets, Players, and Enemies, and design your own game characters. You'll also bring your game to life by making the player character move using the A and B buttons. Let's dive in and start building an awesome game!
Learning Goals Learning Outcomes Teacher Notes

### 1 - Creating a Microbit Project

We have to make a microbit project first.

To do this, we can go to the microbit website https://makecode.microbit.org/. . Then, we can click New Project to start making our Microbit project.

### 2 - Creating a Countdown Timer

For this part, we are going to create a countdown timer that starts from 3.

To add the countdown timer, we can follow the code below. This code will be using the show number and pause blocks that were in the Basic category.

```basic.showNumber(3)
basic.pause(1000)
basic.showNumber(2)
basic.pause(1000)
basic.showNumber(1)
basic.pause(1000)```

### 3 - Creating the Player, Enemy and Bullet Variables

For this project, we are going to create three variables; Bullets, Players and Enemy.

To create our variables, we can click on the Variables category and press the Make a Variable button. We can name these variables Bullets, Players and Enemy.

### 4 - Creating the Player Sprite

Now, we are going to create our player sprite and the enemy sprite.

For our player sprite, it will be on the left side of the screen. We can use the code below to do this.

```let Player: game.LedSprite = null
Player = game.createSprite(2, 4)```

### 5 - Moving the Player Sprite

For this part, we are going to be moving our player sprite using the A and B buttons. The A button will move our player sprite to the left while the B button will move it to the right.

The code below will handle this logic.

```input.onButtonPressed(Button.A, function () {
let Player: game.LedSprite = null
Player.change(LedSpriteProperty.X, -1)
})
```
```input.onButtonPressed(Button.B, function () {
let Player: game.LedSprite = null
Player.change(LedSpriteProperty.X, 1)
})
```

# Unlock the Full Learning Experience

Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.