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

Puzzle Bobble-style Bubble Shooter: The night sky

Shoot bubbles to pop three of a color and drop what they hold up. A hex grid in a 2D array, aiming with atan2, shots that bounce and snap into the grid, a flood fill for groups and another for what still hangs, a ceiling that comes down, and a guide that simulates the shot.

What we are doing

We start with the usual frame: find the canvas, take its 2D context, and a loop that paints a deep blue background about 60 times a second.

```js
const canvas = document.getElementById('game')
const ctx = canvas.getContext('2d')

function draw() {
  ctx.fillStyle = '#1e1b4b'
  ctx.fillRect(0, 0, canvas.width, canvas.height)
}

function loop() {
  draw()
  requestAnimationFrame(loop)
}

requestAnimationFrame(loop)
```

What it means

Your turn

Write the code under the three comment lines, then press Run.

Skills: Drawing on a canvas, The game loop

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