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

Microbit Bop It Game

In this step-by-step lesson, you'll create a 'Bop It' game on your Microbit. You'll learn to create a new project, define variables, set a countdown, generate random numbers, display images, and program buttons. You'll also learn how to handle game over scenarios and add extra actions for an added challenge.
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 lesson, we are going to create an exciting game called 'Bop It' on our Microbit. The game will display a random image on the Microbit's LED display, and you will have to perform the correct action corresponding to that image. You will have 20 seconds to see how many actions you can get right!

    To start, we need to create a new Microbit project.

    2 - Create a variable called ‘action’

    Create a variable called ‘action’, we will use this variable to store and remember a random action. In the on start block, set ‘action’ to -1 by adding this code:

    let action = -1
    

    3 - Add a start countdown block

    Add a start countdown block and set it to 20000 milliseconds (which is 20 seconds).

    let action = -1 
    game.startCountdown(20000)
    

    This means the player has 20 seconds to get as many correct actions as they can!

    4 - Set 'action' to a random number

    In the forever block we want to check if ‘action’ is equal to -1, if it is then we want to set ‘action’ to a random number between 0 and 2.

    basic.forever(function () {
        if (action == -1) {
            action = Math.randomRange(0, 2)
        }
    })
    

    We choose a random number between 0 and 2 as that will give us three possibilities: 0, 1 and 2.

    5 - Display the image

    Next depending on what ‘action’ is now equal to, we are going to display an image on our Microbits telling the user what action they need to do.

    • action = 0 means you should press the A button (arrow left)
    • action = 1 means you should press the B button (arrow right)
    • action = 2 means you should press the A+B buttons (arrows left and right)

    Add the following code to check what 'action' is equal to and show the appropriate image.

    basic.forever(function () {
        if (action == -1) {
            action = Math.randomRange(0, 2)
        }
        if (action == 0) {
            basic.showLeds(`
                . . # . .
                . # . . .
                # . . . .
                . # . . .
                . . # . .
                `)
        } else if (action == 1) {
            basic.showLeds(`
                . . # . .
                . . . # .
                . . . . #
                . . . # .
                . . # . .
                `)
        } else if (action == 2) {
            basic.showLeds(`
                . . # . .
                . # . # .
                # . . . #
                . # . # .
                . . # . .
                `)
        }
    })
    
    
    

    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