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

Land on platforms

What we are doing

A platform catches the player only on the way down, and only when the feet cross its top during this frame. So you can jump up through a platform from below and land on it on the way down, just like the real game.

```js
const oldBottom = player.y + player.h
player.vy += GRAVITY
player.y += player.vy
const bottom = player.y + player.h

// Platforms only catch you on the way down, when your feet cross their top in this frame.
if (player.vy > 0) {
  for (const p of platforms) {
    const over = player.x + player.w - 8 > p.x && player.x + 8 < p.x + p.w
    if (over && oldBottom <= p.y && bottom >= p.y) {
      player.y = p.y - player.h
      player.vy = JUMP
      break
    }
  }
}

// For now the floor still bounces you back up.
```

What it means

Your turn

  1. In update, write oldBottom above the gravity lines and bottom under them.
  2. Write the comment and the landing block, then change the floor comment.

Skills: Collision detection

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