Workshop › Frogger-style Crossing › Step 18 of 22

Get home

What we are doing

Hopping into an empty home fills it and a new frog starts. Hopping onto the bank between homes, or into a full home, costs a life.

```js
let filled // one true/false per home
  filled = HOMES.map(() => false)

  if (frog.y === 0) reachHome()

function reachHome() {
  const i = HOMES.indexOf(frog.x)
  if (i === -1 || filled[i]) {
    die()
    return
  }
  filled[i] = true
  newFrog()
}

    if (filled[i]) {
      ctx.fillStyle = '#86efac'
      ctx.fillRect(col * TILE + 8, TOP + 8, TILE - 16, TILE - 16)
    }
```

What it means

Your turn

  1. Under let state, write let filled; in reset, fill it with falses.
  2. At the end of hop, call reachHome on row 0, and write reachHome under hop.
  3. In draw, show the filled homes.

Skills: Game states

All steps

  1. Road and river
  2. The frog
  3. Keep drawing
  4. Hop
  5. Swipe to hop
  6. Lanes of traffic
  7. Cars
  8. Traffic moves
  9. Hit by a car
  10. Three lives
  11. Play again
  12. Tap to play again
  13. Logs on the river
  14. Stay on the logs
  15. Ride the log
  16. Back in line
  17. Home slots
  18. Get home
  19. Points for progress
  20. Next level
  21. Best score
  22. Build it yourself: a time limit