Keep the level in a variable and change it where the score changes, with a goal that moves up each time.
Almost every game gets harder as you play. Behind it is one number, the level, and one place where it changes.
A game with levels needs a variable, level, that remembers where the player is, and one place where it goes up. This game also keeps a goal: the score the next level needs.
The splash uses join (in Text) to stick the word Level and the number together. Copy it as it is for now.
Make your prediction first. Help opens once you've locked it in.

let enemy: Sprite = null
let level = 1
let goal = 5
function addEnemy () {
enemy = sprites.create(img`
a . . a
a a a a
a 1 1 a
a a a a
`, SpriteKind.Enemy)
enemy.setPosition(80, 10)
enemy.setVelocity(50, 40)
enemy.setBounceOnWall(true)
}
let player = sprites.create(img`
. 4 4 .
4 4 4 4
. 8 8 .
. 8 8 .
`, SpriteKind.Player)
controller.moveSprite(player)
player.setStayInScreen(true)
let coin = sprites.create(img`
. 5 5 .
5 5 4 5
5 4 5 5
. 5 5 .
`, SpriteKind.Food)
coin.setPosition(randint(10, 150), randint(10, 110))
info.setLife(3)
addEnemy()
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
otherSprite.setPosition(randint(10, 150), randint(10, 110))
info.changeScoreBy(1)
if (info.score() >= goal) {
level += 1
goal += 5
game.splash("Level " + level)
addEnemy()
}
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
info.changeLifeBy(-1)
otherSprite.setPosition(80, 10)
})
Read the Player–Food overlap. What is goal after the first level-up?
Collect coins and dodge the enemies. Press A (space) to close each splash.

let enemy: Sprite = null
let level = 1
let goal = 5
function addEnemy () {
enemy = sprites.create(img`
a . . a
a a a a
a 1 1 a
a a a a
`, SpriteKind.Enemy)
enemy.setPosition(80, 10)
enemy.setVelocity(50, 40)
enemy.setBounceOnWall(true)
}
let player = sprites.create(img`
. 4 4 .
4 4 4 4
. 8 8 .
. 8 8 .
`, SpriteKind.Player)
controller.moveSprite(player)
player.setStayInScreen(true)
let coin = sprites.create(img`
. 5 5 .
5 5 4 5
5 4 5 5
. 5 5 .
`, SpriteKind.Food)
coin.setPosition(randint(10, 150), randint(10, 110))
info.setLife(3)
addEnemy()
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
otherSprite.setPosition(randint(10, 150), randint(10, 110))
info.changeScoreBy(1)
if (info.score() >= goal) {
level += 1
goal += 5
game.splash("Level " + level)
addEnemy()
}
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
info.changeLifeBy(-1)
otherSprite.setPosition(80, 10)
})

let enemy: Sprite = null
let level = 1
let goal = 5
function addEnemy () {
enemy = sprites.create(img`
a . . a
a a a a
a 1 1 a
a a a a
`, SpriteKind.Enemy)
enemy.setPosition(80, 10)
enemy.setVelocity(50, 40)
enemy.setBounceOnWall(true)
}
let player = sprites.create(img`
. 4 4 .
4 4 4 4
. 8 8 .
. 8 8 .
`, SpriteKind.Player)
controller.moveSprite(player)
player.setStayInScreen(true)
let coin = sprites.create(img`
. 5 5 .
5 5 4 5
5 4 5 5
. 5 5 .
`, SpriteKind.Food)
coin.setPosition(randint(10, 150), randint(10, 110))
info.setLife(3)
addEnemy()
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
otherSprite.setPosition(randint(10, 150), randint(10, 110))
info.changeScoreBy(1)
if (info.score() >= goal) {
level += 1
goal += 5
game.splash("Level " + level)
addEnemy()
}
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
info.changeLifeBy(-1)
otherSprite.setPosition(80, 10)
})
Follow level and goal coin by coin.
Zoe's level-up:

game.onUpdate(function () {
if (info.score() >= 5) {
level += 1
game.splash("Level " + level)
addEnemy()
}
})
level starts at 1 and goal at 5. Fill in level and goal after each coin.
| score | level | goal |
|---|---|---|
| 0 | 1 | 5 |
| 5 | ||
| 6 | ||
| 10 |
Make a new level come every 3 coins.
Two numbers: the goal you start with and how much it changes by.
Both 3.
Give the player a bonus life at every new level. One block, in the right place.
change life by 1 (Info) goes inside the level-up if.
A new level every 3 coins.
This ticks by itself when your blocks do what is asked.
A bonus life at every new level.
This ticks by itself when your blocks do what is asked.

scene.setBackgroundColor(9)
let player = sprites.create(img`
. 4 4 .
4 4 4 4
. 8 8 .
. 8 8 .
`, SpriteKind.Player)
player.ay = 300
game.onUpdate(function () {
if (player.bottom > 80) {
player.bottom = 80
player.vy = 0
}
})
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
if (player.bottom >= 100) {
player.vy = -150
}
})
Ana raises the floor: the floor if now puts the player's bottom at 80. Her jump still asks bottom ≥ 100. What number should the jump ask about now?
This is your runner from last lesson. Every rock that appears scores a point. Give it levels:
Two new variables in on start: level 1 and goal 10.
The score changes in the timer, so the level-up goes there, just after change score.
Inside the if: change level by 1, change goal by 10, change speed by -20, and a splash.
Every 10 points the runner levels up: a splash, and faster rocks.
This ticks by itself when your blocks do what is asked.
Catch fish with the net. Every 5 fish the level goes up and the fish swim faster. Make the water darker at every level too: one block, in the level-up.
Students keep the level in a variable, change it where the score changes with a goal that moves up, see why a level-up in on game update fires every frame, and add levels to their runner. About 45 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
A level is a variable that starts at 1 and changes by 1. The level-up is an if in the event where the score changes (here the coin overlap): if score ≥ goal, change level by 1, change goal by 5, splash and add an enemy. goal is a target that moves up, so the question is false again until 5 more coins.
The trap is the lesson's misconception: put if score ≥ 5 in on game update and it fires every frame while the score stays 5 or more, so the level races up. The splash uses join ("Level " + level), labelled copy-for-now.
Next lesson keeps what changes per level in a list.
Where the level-up goes. When levels race up, ask how often that block runs.
Stretch: Win the game at level 5: an if inside the level-up with game over (win).
Support: Give students the level and goal variables in the Make starter, so they write only the if in the timer.
Next: a list per level, so each level can have its own background and speed. Skillmap: Jungle Jump Platformer (arcade.makecode.com/skillmaps) moves between level maps.