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

One bubble

What we are doing

A bubble is a colored circle. Colors are kept as a number, an index into COLORS, which makes comparing them easy later. drawBubble draws one; we try it with a test bubble in the middle.

```js
const R = 20 // bubble radius
const COLORS = ['#ef4444', '#f59e0b', '#22c55e', '#3b82f6', '#a855f7']

function drawBubble(x, y, color, r = R) {
  ctx.fillStyle = COLORS[color]
  ctx.beginPath()
  ctx.arc(x, y, r - 1, 0, Math.PI * 2)
  ctx.fill()
}

  drawBubble(200, 260, 3)
```

What it means

Your turn

  1. Under const ctx = ..., leave an empty line and write R and COLORS.
  2. Above function draw() { write drawBubble, with an empty line after it.
  3. In draw, under the background, leave an empty line and write the test call. Press Run.

Skills: Drawing on a canvas, Functions

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