Workshop › Puzzle Bobble-style Bubble Shooter › Step 19 of 31

Bubbles that fall

What we are doing

Popped bubbles should not just vanish. Each one jumps up a little and falls off the screen, pulled by gravity.

```js
let falling // popped and dropped bubbles on their way out: { x, y, vy, r, color }
  falling = []

    const p = cellPos(r, c)
    falling.push({ x: p.x, y: p.y, vy: -2, r: R, color: grid[r][c] })

  for (const f of falling) {
    f.vy += 0.4
    f.y += f.vy
  }
  falling = falling.filter((f) => f.y - f.r < canvas.height)

  for (const f of falling) drawBubble(f.x, f.y, f.color, f.r)
```

What it means

Your turn

  1. Under let shot, write let falling; in reset, under shot = null, write falling = [].
  2. In remove, write the two lines at the top of the loop.
  3. At the start of update, write the gravity loop and the filter line.
  4. In draw, under the grid loop, draw the falling bubbles.

Skills: Velocity and gravity

All steps

  1. The night sky
  2. One bubble
  3. A grid of cells
  4. Draw the grid
  5. Bubbles that nest
  6. The shooter
  7. Aim upwards
  8. Turn with the arrows
  9. Aim with the pointer
  10. Fire!
  11. Fly
  12. Bounce off the walls
  13. Touching something?
  14. Stick into the grid
  15. Smaller steps
  16. Six neighbours
  17. Flood fill
  18. Three in a row pop
  19. Bubbles that fall
  20. Cut them loose
  21. Show the score
  22. Only useful colors
  23. Count the shots
  24. The ceiling comes down
  25. Win or lose
  26. The danger line
  27. The end message
  28. Play again
  29. Best score
  30. A dotted guide
  31. Build it yourself: swap bubbles