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

Aim upwards

What we are doing

The aim is an angle in radians. On the canvas y grows downwards, so straight up is -π/2. A short line from the shooter shows it: Math.cos(aim) is how far right and Math.sin(aim) how far down for each unit along it.

```js
let aim // angle of the shot, in radians

  aim = -Math.PI / 2

  ctx.strokeStyle = 'rgba(255, 255, 255, 0.6)'
  ctx.lineWidth = 2
  ctx.beginPath()
  ctx.moveTo(SHOOTER.x, SHOOTER.y)
  ctx.lineTo(SHOOTER.x + Math.cos(aim) * 80, SHOOTER.y + Math.sin(aim) * 80)
  ctx.stroke()
```

What it means

Your turn

  1. Under let grid ... write let aim ...; in reset, above loaded = pickColor(), write aim = -Math.PI / 2.
  2. In draw, above the loaded bubble, write the six line-drawing lines.

Skills: Drawing on a canvas

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