Workshop › Doodle Jump-style Climber › Step 14 of 24
The six fixed platforms give way to endless random ones. fillPlatforms keeps adding platforms above the highest one
until the screen (plus a margin) is full; the gap grows with the difficulty but never beyond what a bounce can reach.
Platforms that fall below the screen are forgotten.
```js
// A bounce rises about JUMP * JUMP / (2 * GRAVITY) = 172 pixels, so a gap must stay well below that.
const MAX_GAP = 110
let platforms = [{ x: 170, y: START_Y, w: 60, h: 12 }]
let highest = START_Y // world y of the highest platform so far
// Add platforms above the highest one until the screen (and a little more) is full.
function fillPlatforms() {
while (highest > cameraY - 100) {
const d = difficulty(highest)
const gap = 45 + Math.random() * (MAX_GAP - 45) * (0.4 + 0.6 * d)
highest -= gap
platforms.push({ x: Math.random() * (canvas.width - 60), y: highest, w: 60, h: 12 })
}
}
fillPlatforms()
platforms = platforms.filter((p) => p.y < cameraY + canvas.height + 20)
fillPlatforms()
```x is random, keeping the whole platform on screen.START_Y, write the comment and MAX_GAP.let platforms, and write highest under cameraY.difficulty, write the comment and fillPlatforms.update, under the camera line, write the two lines.fillPlatforms() above requestAnimationFrame(loop) at the bottom.Skills: Loops, Game states
← How hard should it be? Miss and fall →