← Arcade advanced skills

Arcade blocks reference

The blocks from Arcade Foundations and Arcade advanced skills, each with what it does. Find them in the MakeCode toolbox; the picture shows the block, the code is the same block as MakeCode JavaScript.

Print a cheat sheet (the whole course or one unit, with a picture of each block)

Sprites and movement

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)
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.

The block

id: create-sprite

scene.setBackgroundColor(9)
set background color

Fills the screen with one colour. Scene.

The block

id: set-background-color

mySprite.setPosition(80, 60)
set position

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

The block

id: set-position

mySprite.x = 80
set x

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

The block

id: set-x

controller.moveSprite(mySprite)
move with buttons

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

The block

id: move-with-buttons

mySprite.setStayInScreen(true)
stay in screen

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

The block

id: stay-in-screen

mySprite.setVelocity(50, 0)
set velocity

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

The block

id: set-velocity

mySprite.vx = 50
set vx

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

The block

id: set-vx

mySprite.setBounceOnWall(true)
bounce on wall

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

The block

id: bounce-on-wall

controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
    blocks
})
on A pressed

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

The block

id: on-a-pressed

Collide and score

sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
    blocks
})
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.

The block

id: on-overlap

otherSprite.destroy()
destroy

Removes a sprite from the game. Sprites.

The block

id: destroy

randint(0, 160)
pick random

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

The block

id: pick-random

info.setScore(0)
set score

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

The block

id: set-score

info.changeScoreBy(1)
change score

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

The block

id: change-score

info.setLife(3)
set life

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

The block

id: set-life

info.changeLifeBy(-1)
change life

Adds or takes away lives. Info.

The block

id: change-life

sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
    otherSprite.destroy()
    info.changeLifeBy(-1)
})
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.

The block

id: hit-costs-a-life

game.onUpdateInterval(1000, function () {
    blocks
})
on game update every

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

The block

id: on-game-update-every

info.startCountdown(30)
start countdown

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

The block

id: start-countdown

game.gameOver(false)
game over

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

The block

id: game-over

Decide

game.onUpdate(function () {
    blocks
})
on game update

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

The block

id: on-game-update

if (condition) {
    blocks
}
if

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

The block

id: if

game.onUpdate(function () {
    if (car.x > 160) {
        car.x = 0
    }
})
check every frame

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

The block

id: check-every-frame

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

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

The block

id: if-else

} else if (condition) {
else if

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

The block

id: else-if

mySprite.x > 150
compare

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

The block

id: compare

enemy.follow(mySprite, 40)
follow

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

The block

id: follow

Collections and tools

let projectile = sprites.createProjectileFromSprite(img`
    . 2 .
    2 4 2
    . 2 .
    `, mySprite, 0, -100)
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.

The block

id: projectile-from-sprite

sprites.allOfKind(SpriteKind.Enemy)
array of sprites of kind

A list of every sprite of a kind in the game right now. Sprites.

The block

id: array-of-sprites-of-kind

for (let value of list) {
    blocks
}
for element of list

Runs its blocks once for each item in the list, with value as that item. Loops.

The block

id: for-element-of-list

let speeds = [40, 60, 90]
list

Many values in order under one name. Places start at 0. Arrays.

The block

id: list

speeds[0]
get value at

The item at a place in the list, counted from 0. Arrays.

The block

id: get-value-at

function spawnEnemy () {
    blocks
}
function

Names a group of blocks. They run only when you call the function. Functions › Make a Function.

The block

id: function

function spawnEnemy (speed: number) {
    blocks
}
function with a parameter

A parameter is a value the caller hands in, so one function can do the job differently each time. Click + on the function block.

The block

id: function-with-a-parameter

Gravity, jumping and levels

let level = 1
set variable

Puts a value in a variable, throwing the old value away. Make the variable in Variables first.

The block

id: set-variable

level += 1
change variable

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

The block

id: change-variable

mySprite.ay = 300
set ay

Acceleration down: the sprite falls faster and faster, like gravity. Sprites; choose ay in the dropdown.

The block

id: set-ay

mySprite.vy = -150
jump

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

The block

id: jump

controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
    if (player.bottom >= 100) {
        player.vy = -150
    }
})
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.

The block

id: jump-from-ground

mySprite.bottom
sprite bottom

The y of the bottom edge of a sprite. Sprites; choose bottom in the x dropdown.

The block

id: sprite-bottom

game.splash("Level 1")
splash

Shows a message and waits for A. Game.

The block

id: splash

if (info.score() >= goal) {
    level += 1
    goal += 5
    game.splash("Level " + level)
}
level up

Goes in the event where the score changes, not in on game update. goal moves up, so the next level is further away.

The block

id: level-up

sprites.destroyAllSpritesOfKind(SpriteKind.Enemy)
destroy all of kind

Removes every sprite of a kind at once. Sprites.

The block

id: destroy-all-of-kind

Power-ups and challenge

rock.setFlag(SpriteFlag.AutoDestroy, true)
auto destroy

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

The block

id: auto-destroy

let shield = false
true or false

A variable can hold true or false, to remember what is happening now. Logic.

The block

id: true-or-false

if (ammo > 0) {
    blocks
    ammo += -1
}
count down

Check there is some left first, then use one up, so the count never goes below zero.

The block

id: count-down

info.onLifeZero(function () {
    blocks
})
on life zero

Runs when the lives reach 0, instead of the usual game over. Info.

The block

id: on-life-zero

info.highScore()
high score

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

The block

id: high-score