← Reference

Arcade Foundations: cheat sheet

Arcade Foundations · Find each block in the MakeCode toolbox (the category is at the end of each line).

Sprites and movement

create sprite

Makes a sprite: a picture the game can move and test. Sprites; click the picture to draw your own. The kind says what it is.

let mySprite = sprites.create(img`
    . . . . . . . .
    . . 5 5 5 5 . .
    . 5 5 5 5 5 5 .
    . 5 f 5 5 f 5 .
    . 5 5 5 5 5 5 .
    . 5 f f f f 5 .
    . . 5 5 5 5 . .
    . . . . . . . .
    `, SpriteKind.Player)
The block

set x

Sets one part of the position. y counts down from the top. Sprites; choose x or y in the dropdown.

mySprite.x = 80
The block

stay in screen

Stops a sprite going off the edge. Sprites › set stay in screen.

mySprite.setStayInScreen(true)
The block

set vx

Speed across: positive moves right, negative moves left. vy is speed down. Sprites; choose vx in the dropdown.

mySprite.vx = 50
The block

on A pressed

Runs its blocks every time A is pressed (space or Z on the keyboard). Controller.

controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
    blocks
})
The block

jump from ground

The jump goes inside an if that asks whether the player is on the floor, so it only works from the ground.

controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
    if (player.bottom >= 100) {
        player.vy = -150
    }
})
The block

set background color

Fills the screen with one colour. Scene.

scene.setBackgroundColor(9)
The block

set position

Puts a sprite at x (across, 0 to 160) and y (down, 0 to 120). The middle is 80, 60. Sprites.

mySprite.setPosition(80, 60)
The block

move with buttons

The arrow keys (or WASD) move the sprite. Add two numbers for the speed across and down. Controller.

controller.moveSprite(mySprite)
The block

set velocity

How far the sprite moves every frame, across and down. It keeps moving until something changes it. Sprites.

mySprite.setVelocity(50, 0)
The block

bounce on wall

The sprite bounces back at the edge of the screen. Sprites › set bounce on wall.

mySprite.setBounceOnWall(true)
The block

change variable

Adds to a variable. Change by -1 counts down. Variables.

level += 1
The block

Collide and score

on overlap

Runs when a sprite of the first kind touches a sprite of the second kind. sprite is the first, otherSprite the second. Sprites › Overlaps.

sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
    blocks
})
The block

set score

Shows a score at the top of the screen. Info.

info.setScore(0)
The block

set life

Shows hearts for lives. At zero lives the game ends by itself. Info.

info.setLife(3)
The block

hit costs a life

A hit destroys what hit you and costs a life, so one touch counts once. At 0 lives the game ends by itself.

sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
    otherSprite.destroy()
    info.changeLifeBy(-1)
})
The block

start countdown

A timer in seconds at the top of the screen; the game ends when it reaches 0. Info.

info.startCountdown(30)
The block

destroy

Removes a sprite from the game. Sprites.

otherSprite.destroy()
The block

pick random

A whole number chosen at random, from the first number to the second. Math.

randint(0, 160)
The block

change score

Adds to the score. Use a negative number to take away. Info.

info.changeScoreBy(1)
The block

change life

Adds or takes away lives. Info.

info.changeLifeBy(-1)
The block

on game update every

A timer: runs its blocks every so many milliseconds (1000 ms is one second). Game.

game.onUpdateInterval(1000, function () {
    blocks
})
The block

Decide

game over

Ends the game: true is a win, false is a loss. Game.

game.gameOver(false)
The block

if

Runs the blocks inside only when the condition is true. Logic.

if (condition) {
    blocks
}
The block

if else

Exactly one part runs: the first when the condition is true, else the second. Click + on an if block.

if (condition) {
    blocks
} else {
    blocks
}
The block

follow

The engine steers one sprite towards another at a speed. Sprites.

enemy.follow(mySprite, 40)
The block

on game update

Runs its blocks every frame, about 30 times a second. Put an if here to keep checking something. Game.

game.onUpdate(function () {
    blocks
})
The block

check every frame

An if inside on game update is asked every frame, so it acts the moment its question becomes true.

game.onUpdate(function () {
    if (car.x > 160) {
        car.x = 0
    }
})
The block

else if

Another question, asked only if the ones above were false. The first true one wins.

} else if (condition) {
The block

compare

Compares two numbers: true or false. Logic; drag a sprite x block into it from Sprites.

mySprite.x > 150
The block

jump

A jump is a speed upwards (negative vy); gravity slows it and brings the sprite back down.

mySprite.vy = -150
The block

Fire

projectile from sprite

Fires a sprite of kind Projectile from another sprite, with a speed across and down. It is destroyed when it leaves the screen. Sprites.

let projectile = sprites.createProjectileFromSprite(img`
    . 2 .
    2 4 2
    . 2 .
    `, mySprite, 0, -100)
The block

Final challenge: Space dodger

auto destroy

The sprite is removed once it leaves the screen, so old ones do not pile up. Sprites › set flag.

rock.setFlag(SpriteFlag.AutoDestroy, true)
The block

high score

The best score so far in this browser. The game over screen shows it by itself. Info.

info.highScore()
The block