Workshop › Frogger-style Crossing › Step 9 of 22
If a car covers the frog's square, the frog is hit and a new one starts from the bottom. The frog's box is shrunk a little, so only a real overlap counts.
```js
function newFrog() {
frog = { x: 5, y: START_ROW }
}
function laneAt(row) {
return LANES.find((lane) => lane.row === row)
}
function die() {
newFrog()
}
function hitByCar(lane) {
return items(lane).some((x) => frog.x + 0.15 < x + lane.len && frog.x + 0.85 > x)
}
const lane = laneAt(frog.y)
if (!lane) return
if (hitByCar(lane)) die()
```laneAt finds the lane in the frog's row, or undefined on the safe rows.x to x + len overlaps the frog when the car starts before the frog ends and ends after it starts.
The frog counts as 0.15 to 0.85 of its square.die just starts a new frog for now.offset line, write newFrog and laneAt.DIRECTIONS, write die; above update, write hitByCar.update, write the three check lines.Skills: Collision detection