← Teacher guide

Overlaps and kinds

Students make overlap events that run when two sprites touch, and see that the kinds named in the event decide which event runs.

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 8 min · Mix it up 3 min · Make 9 min · Fruit stall 3 min

Before class

An overlap is two sprites touching. on sprite of kind Player overlaps otherSprite of kind Food (Sprites › Overlaps) is an event: it runs when a sprite of the first kind touches a sprite of the second kind, and never for any other pair. Inside it, sprite is the first one (the player) and otherSprite the second (the coin that was touched). Every sprite has a kind: Player, Food, Enemy or Projectile. The create block starts with of kind Player, so a forgotten kind is the most common bug: a coin made as a Player is never collected. change score by (Info) shows a score at the top of the screen.

Running the lesson

  1. Predict: most students expect the coin to vanish. The real point is why: ask which two kinds the event names.
  2. Investigate: the match shows that a pair no event names (Food and Enemy) does nothing. Ava's star is the default kind left as Player.
  3. Modify: a second coin needs no new event: one event serves every Food sprite.
  4. Mix it up: move with buttons speeds, from lesson 2.
  5. Make: check every create block's kind before testing. Two overlap events, one per kind.

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)

Kinds decide which overlap runs, and sprite versus otherSprite. When a touch does nothing, ask them to read out the kinds of both sprites and the kinds the event names.

When students get stuck

What you will seeA question to askThe fix
Touching the coin does nothing.What kind is the coin, and what kinds does the overlap event name?Make the coin of kind Food (the dropdown in its create block), to match Player–Food in the event.
The wrong sprite disappears (the player instead of the coin).Which sprite does destroy name: sprite or otherSprite?otherSprite is the one of the second kind (Food). Drag otherSprite into destroy.
The score jumps up by many points in one touch.What happens to the coin after the touch?If it stays where it is, the event runs again every frame. Destroy it (next lesson looks at this).

Answers to the checks

  1. Predict: You steer the player onto the coin. What happens?
    The coin vanishes and a score of 1 appears at the top of the screen. The player is of kind Player and the coin of kind Food, so the Player–Food overlap event runs.
  2. Who touches whom?: Match what touches with what happens in this game.
    the player touches the coin (Food) → B. the score goes up 1 and the coin vanishes; the player touches the spike (Enemy) → A. the score goes down 1 and the spike is destroyed; the coin and the spike touch → C. nothing: no event names Food and Enemy
  3. Which sprite?: In the Player–Food event, which sprite is otherSprite?
    The coin it touched
    The event hands over both sprites: sprite is the one of the first kind (Player), otherSprite the one of the second kind (Food). So destroy otherSprite removes the coin that was touched.
  4. Ava's star: Ava added a star to her game and steers onto it. Nothing happens: no score, the star stays. Why?
    The star was made of kind Player, so no Player–Food event runs
    The create block starts with of kind Player, and Ava did not change it. Her overlap event is for Player touching Food, so a Player touching a Player runs nothing. Choose Food in the star's kind dropdown.
  5. Mix it up: The ship has move with buttons with speeds 100 and 0. Which arrow keys move it?
    Left and right only
    The first number is the speed across (100) and the second the speed up and down (0), so only left and right do anything.

Solutions

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

Modify › Worth more

The program as blocks
Show as code
let mySprite = sprites.create(img`
    . 4 4 .
    4 4 4 4
    . 8 8 .
    . 8 8 .
    `, SpriteKind.Player)
controller.moveSprite(mySprite)
let coin = sprites.create(img`
    . 5 5 .
    5 5 4 5
    5 4 5 5
    . 5 5 .
    `, SpriteKind.Food)
coin.setPosition(120, 60)
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
    otherSprite.destroy()
    info.changeScoreBy(5)
})

Modify › A second coin

The program as blocks
Show as code
let mySprite = sprites.create(img`
    . 4 4 .
    4 4 4 4
    . 8 8 .
    . 8 8 .
    `, SpriteKind.Player)
controller.moveSprite(mySprite)
let coin = sprites.create(img`
    . 5 5 .
    5 5 4 5
    5 4 5 5
    . 5 5 .
    `, SpriteKind.Food)
coin.setPosition(120, 60)
let coin2 = sprites.create(img`
    . 5 5 .
    5 5 4 5
    5 4 5 5
    . 5 5 .
    `, SpriteKind.Food)
coin2.setPosition(40, 100)
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
    otherSprite.destroy()
    info.changeScoreBy(5)
})

Make

The program as blocks
Show as code
info.setScore(0)
let mySprite = sprites.create(img`
    . 4 4 .
    4 4 4 4
    . 8 8 .
    . 8 8 .
    `, SpriteKind.Player)
controller.moveSprite(mySprite)
mySprite.setStayInScreen(true)
let apple = sprites.create(img`
    . . 7 .
    . 2 2 .
    2 2 2 2
    . 2 2 .
    `, SpriteKind.Food)
apple.setPosition(130, 30)
let worm = sprites.create(img`
    . a a .
    a . . a
    a . . .
    . a a a
    `, SpriteKind.Enemy)
worm.setPosition(40, 90)
sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function (sprite, otherSprite) {
    info.changeScoreBy(1)
    otherSprite.destroy()
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
    info.changeScoreBy(-1)
    otherSprite.destroy()
})

Change a fruit stall game

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

Stretch and support

Stretch: Add a second kind of good food worth 3 points. Which kinds does its event need?

Support: Give students the Food and Enemy sprites already made with the right kinds, and ask them to build only the two overlap events.

Exit ticket

A coin is made of kind Player. The game has a Player–Food overlap event. Will touching the coin score? Why?

No. The event only runs when a Player touches a Food sprite. The coin is a Player, so no event runs. Change its kind to Food.

What each step is for

Where it leads

Next lesson adds lives and a game that ends. Class ideas: a recycling sorter (paper is Food, plastic is Enemy); design a game where the kinds are swapped: what changes?