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.
Open the makecode.com website and create a new Microbit project.
Go to the Makecode.com Microbit website using the link below and click on the 'New Project' button underneath the 'My Projects' heading.
Install the micro:bit app on your iPad or tablet.
Open the app, tap 'Create code' and then create a new project.
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)
In the Variables toolbox, create a new variable by clicking the 'Make a Variable' button.
Once you click this button a box will appear asking what you want to call your variable. Give it a name that reminds you what you will be using it for. For example, if you wanted to keep track of your score in a game, you would create a variable called 'score'.
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?
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.
In the Variables toolbox, create a new variable by clicking the 'Make a Variable' button.
Once you click this button a box will appear asking what you want to call your variable. Give it a name that reminds you what you will be using it for. For example, if you wanted to keep track of your score in a game, you would create a variable called 'score'.
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