Game Microbit
Advanced
50 mins
205 points
What you need:
  • Chromebook/Laptop/PC

Microbit Pong Game - Part 1

In this project we will be creating a Pong game on our Microbit.

Pong was one of the earliest ever video games, created back in 1972!

We will be using the buttons on the Microbit to move our paddle left & right to make the ball bounce back up the screen.

1 - Create a new Microbit project

Open the makecode.com website and create a new Microbit project.


2 - Create a sprite variable called 'Paddle'

On start, we need a sprite variable for our Paddle. The Paddle should stay at the bottom of the screen and move left & right.

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

3 - Program the buttons

Make the Paddle sprite move left when you press A and move right when you press B.

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

Can you figure out how to make it move left yourself?

see the code

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

4 - Create a sprite variable called 'Ball'

Now we need to create a sprite variable for our Ball that our Paddle will try to deflect. Make the Ball start up the top of the screen.

see the code

See code
let Ball = game.createSprite(randint(0, 4), 0)

5 - Create a variable called 'YDirection'

We need to create a variable for the y-coordinate of the Ball on the screen called YDirection.

On start, we should set YDirection to 1 (more on this in the next section!).

let Paddle: game.LedSprite = null
Paddle = game.createSprite(2, 4)
let YDirection = 1


Join our club 😃

To view the remaining 7 steps and access hundreds of other coding projects please login or create an account.

Copyright Notice
This lesson is copyright of Coding Ireland. 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