Workshop › Endless Runner › Step 16 of 19

Birds

What we are doing

After a while, some obstacles are birds flying low: 30% of the time once the distance passes 1500. They are drawn in orange.

```js
function spawn() {
  // Birds only show up once the player has got used to jumping.
  if (distance > 1500 && Math.random() < 0.3) {
    obstacles.push({ x: canvas.width, y: GROUND - 50, w: 34, h: 20, bird: true })
  } else {
    obstacles.push({ x: canvas.width, y: GROUND - 40, w: 20, h: 40, bird: false })
  }

    ctx.fillStyle = o.bird ? '#b45309' : '#15803d'
```

What it means

Your turn

  1. In spawn, replace the push line with the comment and the if ... else block.
  2. In draw, choose the color with o.bird ? '#b45309' : '#15803d'.

Skills: Game states

All steps

  1. The ground
  2. The runner
  3. Draw again and again
  4. Gravity
  5. Jump
  6. Short hops
  7. Tap to jump
  8. Things that come at you
  9. Cacti keep coming
  10. Wait for the start
  11. Crash
  12. Try again
  13. Faster and faster
  14. Remember the best run
  15. The score counter
  16. Birds
  17. Which keys are down?
  18. Duck
  19. Build it yourself: jump buffering