← Teacher guide

Score and lives

Students give the player lives, make a hit cost one life, and see that the engine ends the game at 0 lives and that an overlap runs every frame while sprites touch.

Arcade Foundations · Collide and score · about 40 minutes · Open the student lesson

Classroom resources

Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Run 7 min · Investigate 10 min · Modify 7 min · Mix it up 3 min · Make 9 min · Dodgeball 4 min

Before class

Info blocks keep a score and lives (hearts) at the top of the screen. When the lives reach 0, Arcade ends the game by itself. One important fact: an overlap event runs every frame (about 30 times a second) while the two sprites still touch. If the enemy is not destroyed, one touch takes life after life, and the game ends at once. Timers (a new enemy every second) are next lesson; here the rocks are made at the start and flown in with a velocity.

Running the lesson

  1. Predict: many students expect lives to go below 0, or that a game over block is needed. The engine does it. Ask the 'no game over block' group to run it and watch.
  2. Run: count the hearts aloud as they go.
  3. Investigate: Sam's dodger is the lesson's key bug: an overlap runs every frame while sprites touch.
  4. Mix it up: kinds and velocity, from earlier lessons.
  5. Make: students who forget destroy lose all three lives at once: let them find it.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

The hard part (on purpose)

An overlap runs every frame while sprites touch, so one hit takes every life. Ask what happens to the enemy after it touches the player.

When students get stuck

What you will seeA question to askThe fix
One touch ends the game.What happens to the enemy after it touches the player?Nothing, so the overlap runs again next frame. Add destroy otherSprite inside the overlap event.
No hearts at the top of the screen.Is there a set life block in on start?Add set life to 3 (Info). Lives appear only once they are set.
Touching a rock does nothing.What kind are the rocks, and what kinds does the overlap name?The rocks are Enemy; the event must be Player with Enemy.

Answers to the checks

  1. Predict: The player has 3 lives and cannot move. Three rocks fly at it. What happens?
    Each rock that hits takes a life and is destroyed. After three hits the lives reach 0, and Arcade shows GAME OVER by itself: you never need a game over block for running out of lives.
  2. Count the lives: Play this game in your head. Fill in the lives after each thing happens.
    2, 2, 3, 2
    Only a touch runs an overlap event, so a rock that flies past changes nothing. The heart's Player–Food event adds one.
  3. Sam's dodger: Sam's player touches one rock and the game is over straight away, though he started with 3 lives. Why?
    The rock is not destroyed, so the overlap event runs again every frame while they touch
    An overlap event runs every frame (about 30 times a second) while the two sprites still touch. The rock is still touching after the first life is gone, so the next frame takes another. Destroy the rock (or move it away) in the event.
  4. Kai's ending: Kai wants his game to end when the lives run out. What does he need to add?
    Nothing: the engine ends the game at 0 lives
    Arcade ends the game by itself when the lives reach 0.
  5. Mix it up: A coin of kind Food moves left towards the player at vx -30. When it reaches the player, which event runs?
    The Player–Food overlap
    The engine carries the coin to the player. It is Food, so the Player–Food event runs.

Solutions

One possible solution for each task. Other correct programs are fine.

Modify › More hearts

The program as blocks
Show as code
info.setLife(5)
let mySprite = sprites.create(img`
    . 4 4 .
    4 4 4 4
    . 8 8 .
    . 8 8 .
    `, SpriteKind.Player)
mySprite.setPosition(20, 60)
controller.moveSprite(mySprite)
mySprite.setStayInScreen(true)
let heart = sprites.create(img`
    2 2 . 2 2
    2 2 2 2 2
    . 2 2 2 .
    . . 2 . .
    `, SpriteKind.Food)
heart.setPosition(80, 100)
let rock = sprites.create(img`
    . e e .
    e e e e
    e e e e
    `, SpriteKind.Enemy)
rock.setPosition(160, 30)
rock.vx = -40
let rock2 = sprites.create(img`
    . e e .
    e e e e
    e e e e
    `, SpriteKind.Enemy)
rock2.setPosition(240, 60)
rock2.vx = -40
let rock3 = sprites.create(img`
    . e e .
    e e e e
    e e e e
    `, SpriteKind.Enemy)
rock3.setPosition(320, 90)
rock3.vx = -40
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
    info.changeLifeBy(-1)
    otherSprite.destroy()
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
    info.changeLifeBy(1)
    otherSprite.destroy()
})

Modify › A point too

The program as blocks
Show as code
info.setLife(5)
let mySprite = sprites.create(img`
    . 4 4 .
    4 4 4 4
    . 8 8 .
    . 8 8 .
    `, SpriteKind.Player)
mySprite.setPosition(20, 60)
controller.moveSprite(mySprite)
mySprite.setStayInScreen(true)
let heart = sprites.create(img`
    2 2 . 2 2
    2 2 2 2 2
    . 2 2 2 .
    . . 2 . .
    `, SpriteKind.Food)
heart.setPosition(80, 100)
let rock = sprites.create(img`
    . e e .
    e e e e
    e e e e
    `, SpriteKind.Enemy)
rock.setPosition(160, 30)
rock.vx = -40
let rock2 = sprites.create(img`
    . e e .
    e e e e
    e e e e
    `, SpriteKind.Enemy)
rock2.setPosition(240, 60)
rock2.vx = -40
let rock3 = sprites.create(img`
    . e e .
    e e e e
    e e e e
    `, SpriteKind.Enemy)
rock3.setPosition(320, 90)
rock3.vx = -40
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
    info.changeLifeBy(-1)
    otherSprite.destroy()
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
    info.changeLifeBy(1)
    info.changeScoreBy(1)
    otherSprite.destroy()
})

Make

The program as blocks
Show as code
info.setLife(3)
let mySprite = sprites.create(img`
    . 4 4 .
    4 4 4 4
    . 8 8 .
    . 8 8 .
    `, SpriteKind.Player)
mySprite.setPosition(20, 60)
controller.moveSprite(mySprite)
mySprite.setStayInScreen(true)
let rock = sprites.create(img`
    . e e .
    e e e e
    e e e e
    `, SpriteKind.Enemy)
rock.setPosition(160, 30)
rock.vx = -40
let rock2 = sprites.create(img`
    . e e .
    e e e e
    e e e e
    `, SpriteKind.Enemy)
rock2.setPosition(240, 60)
rock2.vx = -40
let rock3 = sprites.create(img`
    . e e .
    e e e e
    e e e e
    `, SpriteKind.Enemy)
rock3.setPosition(320, 90)
rock3.vx = -40
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
    info.changeLifeBy(-1)
    otherSprite.destroy()
})

Change a dodgeball game

Open task: any program that does what the step asks.

Stretch and support

Stretch: Add a coin worth points, so there is something to chase as well as dodge.

Support: Give students the overlap event already placed, and ask them to fill in the two blocks inside.

Exit ticket

In a dodge game one touch takes all three lives. What one block is missing, and why does it matter?

destroy otherSprite in the Player–Enemy overlap. The overlap runs every frame while the sprites touch, so without it the same enemy takes a life each frame.

What each step is for

Where it leads

Next lesson: a timer that sends a new rock every second, for as long as the game lasts.