Workshop › Doodle Jump-style Climber › Step 22 of 24

Traps

What we are doing

Sometimes a brown trap platform appears halfway between two real ones. It looks like a way up, but it will break.

```js
const COLORS = { normal: '#16a34a', moving: '#2563eb', breaking: '#a16207' }

    // Sometimes a trap halfway to the next platform: it breaks instead of bouncing.
    if (Math.random() < 0.15 + 0.25 * d) {
      platforms.push({ x: Math.random() * (canvas.width - 60), y: highest + gap / 2, w: 60, h: 12, kind: 'breaking', vx: 0 })
    }
```

What it means

Your turn

  1. Add breaking: '#a16207' to COLORS.
  2. In fillPlatforms, under platforms.push(platform), write the comment and the trap block.

Skills: Game states

All steps

  1. The jumper
  2. Draw again and again
  3. Gravity
  4. Bounce
  5. Steer left and right
  6. Through the sides
  7. Half here, half there
  8. Touch steering
  9. Platforms
  10. Land on platforms
  11. A camera that follows
  12. Lines on the wall
  13. How hard should it be?
  14. Endless platforms
  15. Miss and fall
  16. Play again
  17. Tap to play again
  18. Score is height
  19. Best score
  20. Kinds of platform
  21. Moving platforms
  22. Traps
  23. It breaks!
  24. Build it yourself: springs