Today you're a game programmer. The people who make the games you play don't write everything perfectly the first time — they build a small piece, run it, and watch what happens. When something goes wrong, that's called a bug, and finding and fixing it is a huge part of the job.
We're going to build a platform game where you guide a character across ledges to reach a goal — while dodging danger. Watch the board as we model each piece, then build it on your own device and press play to see what it does. Keep your Investigation Journal handy, because you'll be catching at least one bug today.
A platform game is a game where you guide a character across ledges and platforms to reach somewhere. Mario, Sonic and Hollow Knight all work this way. The ground is never flat: there are gaps to clear, ledges at different heights and platforms hanging in mid-air, so the only way forward is to run and jump.
That means your character needs a small set of abilities — moving left and right, jumping, and something to avoid — and the level is built to test them. Everything you are about to code today is one of those abilities.
Go to the arcade.makecode.com website and create a new project.
Create a new Arcade project using the makecode.com website.
A sprite is a character or object in the game that the code can move around. In this game you will control one sprite and move it from the start of the map to the goal at the end.
Add the following code to your project to create your sprite. Clicking the little picture inside the block opens the sprite editor, a grid where you colour in your character square by square.
let mySprite = sprites.create(img`
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 f f 5 5 5 5 f f 5 5 5 5 5
5 5 5 f f 5 5 5 5 f f 5 5 5 5 5
5 5 5 f f 5 5 5 5 f f 5 5 5 5 5
5 5 5 f f f f 5 5 f f f f 5 5 5
5 5 5 f f f f 5 5 f f f f 5 5 5
5 5 5 f f f f 5 5 f f f f 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 f 5 5 5 5 5 5 5 5 5 5 5 f 5 5
5 f f 5 5 5 5 5 5 5 5 5 f f 5 5
5 5 f f f f f f f f f f f 5 5 5
5 5 f f f f f f f f f f 5 5 5 5
5 5 5 f f f f f f f f 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
`, SpriteKind.Player)
Click on the gray box in the sprite block to open the Editor. You can choose a sprite from the Gallery or you can paint your own sprite using the Editor.
In the game we will use the left and right buttons to move our sprite.
Add the following new code:
let mySprite = sprites.create(img`
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 f f 5 5 5 5 f f 5 5 5 5 5
5 5 5 f f 5 5 5 5 f f 5 5 5 5 5
5 5 5 f f 5 5 5 5 f f 5 5 5 5 5
5 5 5 f f f f 5 5 f f f f 5 5 5
5 5 5 f f f f 5 5 f f f f 5 5 5
5 5 5 f f f f 5 5 f f f f 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 f 5 5 5 5 5 5 5 5 5 5 5 f 5 5
5 f f 5 5 5 5 5 5 5 5 5 f f 5 5
5 5 f f f f f f f f f f f 5 5 5
5 5 f f f f f f f f f f 5 5 5 5
5 5 5 f f f f f f f f 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
`, SpriteKind.Player)
controller.moveSprite(mySprite, 100, 0)
You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.