A variable that holds true or false remembers whether a power-up is on, so an overlap can ask about it.
A mushroom in Mario, a power pellet in Pac-Man, a shield in a space shooter: each one is a variable that is true for a while.
A variable can hold true or false (in Logic). In this game shield starts false. Catching a yellow star sets it to true. When a rock hits, if shield asks whether it is true right now: true smashes the rock for 5 points, false costs a life.
Make your prediction first. Help opens once you've locked it in.

let rock: Sprite = null
let star: Sprite = null
let shield = false
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
otherSprite.destroy()
if (shield) {
info.changeScoreBy(5)
} else {
info.changeLifeBy(-1)
}
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
otherSprite.destroy()
shield = true
scene.setBackgroundColor(8)
})
scene.setBackgroundColor(15)
let ship = sprites.create(img`
8 8 . . . . . .
8 9 9 9 9 . . .
8 9 1 1 9 9 9 9
8 9 9 9 9 . . .
8 8 . . . . . .
`, SpriteKind.Player)
ship.setPosition(20, 60)
controller.moveSprite(ship, 0, 100)
ship.setStayInScreen(true)
info.setLife(3)
game.onUpdateInterval(1000, function () {
rock = sprites.create(img`
. e e e .
e e d e e
e d e e e
. e e e .
`, SpriteKind.Enemy)
rock.setPosition(160, randint(10, 110))
rock.vx = -50
info.changeScoreBy(1)
})
game.onUpdateInterval(5000, function () {
star = sprites.create(img`
. . 5 . .
5 5 5 5 5
. 5 5 5 .
. 5 . 5 .
`, SpriteKind.Food)
star.setPosition(160, randint(10, 110))
star.vx = -30
})
Read the two overlap events. The background turns dark blue while the shield is on.
Catch a star (one floats past every 5 seconds), then fly into the rocks. Is this power-up fair?

let rock: Sprite = null
let star: Sprite = null
let shield = false
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
otherSprite.destroy()
if (shield) {
info.changeScoreBy(5)
} else {
info.changeLifeBy(-1)
}
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
otherSprite.destroy()
shield = true
scene.setBackgroundColor(8)
})
scene.setBackgroundColor(15)
let ship = sprites.create(img`
8 8 . . . . . .
8 9 9 9 9 . . .
8 9 1 1 9 9 9 9
8 9 9 9 9 . . .
8 8 . . . . . .
`, SpriteKind.Player)
ship.setPosition(20, 60)
controller.moveSprite(ship, 0, 100)
ship.setStayInScreen(true)
info.setLife(3)
game.onUpdateInterval(1000, function () {
rock = sprites.create(img`
. e e e .
e e d e e
e d e e e
. e e e .
`, SpriteKind.Enemy)
rock.setPosition(160, randint(10, 110))
rock.vx = -50
info.changeScoreBy(1)
})
game.onUpdateInterval(5000, function () {
star = sprites.create(img`
. . 5 . .
5 5 5 5 5
. 5 5 5 .
. 5 . 5 .
`, SpriteKind.Food)
star.setPosition(160, randint(10, 110))
star.vx = -30
})

let rock: Sprite = null
let star: Sprite = null
let shield = false
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
otherSprite.destroy()
if (shield) {
info.changeScoreBy(5)
} else {
info.changeLifeBy(-1)
}
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
otherSprite.destroy()
shield = true
scene.setBackgroundColor(8)
})
scene.setBackgroundColor(15)
let ship = sprites.create(img`
8 8 . . . . . .
8 9 9 9 9 . . .
8 9 1 1 9 9 9 9
8 9 9 9 9 . . .
8 8 . . . . . .
`, SpriteKind.Player)
ship.setPosition(20, 60)
controller.moveSprite(ship, 0, 100)
ship.setStayInScreen(true)
info.setLife(3)
game.onUpdateInterval(1000, function () {
rock = sprites.create(img`
. e e e .
e e d e e
e d e e e
. e e e .
`, SpriteKind.Enemy)
rock.setPosition(160, randint(10, 110))
rock.vx = -50
info.changeScoreBy(1)
})
game.onUpdateInterval(5000, function () {
star = sprites.create(img`
. . 5 . .
5 5 5 5 5
. 5 5 5 .
. 5 . 5 .
`, SpriteKind.Food)
star.setPosition(160, randint(10, 110))
star.vx = -30
})
Trace a rock hitting the ship.
Fill in what happens when a rock hits the ship.
| shield | lives before | lives after | score change |
|---|---|---|---|
| false | 3 | ||
| true | 3 | ||
| false | 1 |
Which needs true or false, and which needs a number?
Make the shield break after it smashes one rock.
The shield should break when it smashes a rock: inside if shield, after the points.
set shield to false, and set the background back to 15 (black).
If the shield is already on, a star is worth 3 points.
In the star overlap, before shield is set to true: if shield, change score by 3.
The shield breaks after one smash.
This ticks by itself when your blocks do what is asked.
A star caught while the shield is already on is worth 3 points.
This ticks by itself when your blocks do what is asked.
colours is 9, 4, 2, 7 and level is 2. What number does colours[level] give?
A ghost chases you. A power pellet appears every 6 seconds. Make it a power-up:
hunting is false at the start,A new variable, hunting, set to false in on start.
The pellet overlap: destroy the pellet, set hunting to true, and change the background.
The ghost overlap: if hunting, score 5, set hunting to false and put the background back; else lose a life. Either way, send the ghost to the corner.
A power pellet: catch it and the next ghost you touch is worth 5 points, not a life.
This ticks by itself when your blocks do what is asked.
Find the key, then reach the door. Right now the door opens with no key. Use hasKey so the door only opens if you have the key, and if you don't, splash "Locked!" and move the explorer back a step (or the splash comes back every frame).
Students use a true or false variable to remember whether a shield is on, see that it stays true until a block sets it back, and build a power pellet. About 45 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
A variable can hold true or false (Logic). A power-up is three parts: a variable that remembers it (shield), an event that changes it (catching a star sets it to true) and a rule that uses it (if shield in the rock overlap).
The misconception: a true or false variable stays as it is until a block changes it, so a shield set once lasts for ever. Modify fixes it the simplest way (break after one smash); next lesson makes it run out with a countdown.
Setting it back. When a power-up never ends, ask which block sets it to false.
Stretch: Two pellets in a row: count the ghosts eaten while hunting, and give 5, then 10.
Support: Give students the hunting variable and the pellet overlap, so they write only the if in the ghost overlap.
Next: run out, a number that counts down so a power-up lasts a set time. Skillmap: Save the Galaxy (arcade.makecode.com/skillmaps) adds power-ups to a shooter.