Workshop › Frogger-style Crossing › Step 14 of 22

Stay on the logs

What we are doing

The river is deadly: in a log lane, the frog must stand on a log, which means its middle must be over one. Otherwise it falls in the water.

```js
function onLog(lane) {
  const middle = frog.x + 0.5
  return items(lane).some((x) => middle > x && middle < x + lane.len)
}

  if (!lane.log) {
    if (hitByCar(lane)) die()
    return
  }
  if (!onLog(lane)) {
    die()
    return
  }
```

What it means

Your turn

  1. Above update, write onLog.
  2. In update, split the check for road and river as shown.

Skills: Collision detection

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