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

Microbit Zombies

In this step-by-step lesson, you'll create a thrilling multiplayer game using microbits. You'll start by setting up a new project, creating variables for health and infection status, and setting up radio groups for communication. You'll then code your microbit to display health status and infection, lose health when near an infected microbit, and eventually become infected. The game begins with a random infection and continues until all players are infected. Enjoy the game!
Learning Goals Learning Outcomes Teacher Notes Lesson Files

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Create a new microbit project

    In this game we will have a health value and an infected value. At the start of the game everyone's health will be set to 9 and infected will be false.

    Randomly someone in the group will be infected (infected = true and health = 0). If you get too close to their microbit then your health will start going down. Once your health is 0 you will become one of the infected zombie microbits!

    2 - Create two variables

    Create two variables:

    1. 'health' to remember our health value
    2. 'infected' to remember if we're infected or not

    Once you've created the variables, add the following code to set your 'health' to 9 and 'infected' to false:

    let infected = false
    let health = 9
    

    3 - Set the radio group

    As this is a miltiplayer game, we will be using the radios in your microbits to broadcast to each other. To do this we need to make sure we're all on the same radio group.

    Add the 'set radio group' block to your code:

    let infected = false
    let health = 9
    infected = false
    radio.setGroup(1)
    

    4 - Display if you're infected or not

    Our microbits will show our current health value and whether we're infected or not.

    If you are infected (infected = true) then show a skull icon and broadcast the word "zombie". Players that are close enough to receive this message will start getting infected!

    If you are not infected (infected = false) then show a happy face icon and also show your current health value.

    Add the following code into the 'forever' block:

    basic.forever(function () {
        if (infected) {
            basic.showIcon(IconNames.Skull)
            radio.sendString("zombie")
        } else {
            basic.showIcon(IconNames.Happy)
            basic.showNumber(health)
        }
    })
    

    5 - Lose health

    Next we will program what happens when we receive the "zombie" message from an infected microbit. If you're too close to an infected microbit then you start losing health and we'll show a warning icon! Add the following code:

    radio.onReceivedString(function (receivedString) {
        if (radio.receivedPacket(RadioPacketProperty.SignalStrength) > -60) {
            health += -1
            basic.showIcon(IconNames.Angry)
        }
    })
    

    We're using the signal strength of the received message to determine how close the other microbit is. If it's greater than or equal to -60 then we're too close!

    'signal strength' the value ranges from -128 to -42 (-128 means a weak signal and -42 means a strong one).

    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.

    Copyright Notice
    This lesson is copyright of DigitalSkills.org. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more