Workshop › Flappy-style Bird › Step 16 of 30
The test pipe goes away; the list starts empty. addPipe pushes a new pipe at the right edge, with its opening at a
random height that never touches the top or the bottom.
```js
let pipes = []
function addPipe() {
const gapY = 60 + Math.random() * (canvas.height - GAP - 120)
pipes.push({ x: canvas.width, gapY })
}
```[] is an empty array; pipes.push(...) adds an item to its end.Math.random() is a random number from 0 up to 1. Times 320 (600 - 160 - 120) it is 0 to 320; plus 60 it is 60 to
380, so the opening always keeps a 60 pixel margin from the edges.{ x: canvas.width, gapY } is short for { x: canvas.width, gapY: gapY }.pipes to start as an empty array [].pointerdown line, leave an empty line and write addPipe. Press Run.Skills: Arrays and objects
← The world moves, not the bird A pipe every 90 frames →