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

A dotted guide

What we are doing

The short aiming line becomes a dotted path that follows the shot, bouncing off the walls, up to the bubble it would hit. Bank shots get much easier.

```js
// The path the shot will take, bouncing off the walls, until it would touch a bubble.
function guide() {
  let x = SHOOTER.x
  let y = SHOOTER.y
  let vx = Math.cos(aim) * 4
  const vy = Math.sin(aim) * 4
  ctx.fillStyle = 'rgba(255, 255, 255, 0.5)'
  for (let i = 1; i < 200; i++) {
    x += vx
    y += vy
    if (x < R || x > canvas.width - R) vx = -vx
    if (touches(x, y)) break
    if (i % 5 === 0) ctx.fillRect(x - 1.5, y - 1.5, 3, 3)
  }
}

  if (state === 'playing') guide()
```

What it means

Your turn

  1. Above function draw() {, write the comment and guide.
  2. In draw, replace the six lines that draw the aiming line with if (state === 'playing') guide().

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