Workshop › Puzzle Bobble-style Bubble Shooter › Step 10 of 31
A shot is a bubble in flight: a position, a velocity along the aim (SPEED pixels per frame), and the loaded color. Firing
moves the next bubble into the shooter. Space shoots, and so does letting go of the pointer.
```js
const SPEED = 12
let shot // the bubble in flight: { x, y, vx, vy, color }, or null
shot = null
function shoot() {
if (shot) return
shot = { x: SHOOTER.x, y: SHOOTER.y, vx: Math.cos(aim) * SPEED, vy: Math.sin(aim) * SPEED, color: loaded }
loaded = next
next = pickColor()
}
else if (event.key === ' ') shoot()
canvas.addEventListener('pointerup', shoot)
if (shot) drawBubble(shot.x, shot.y, shot.color)
```shot is null while nothing flies; shoot does nothing if a bubble is already flying.SPEED along the aim, in the loaded color; then the next bubble is
loaded and a new next is picked.SHOOTER write SPEED; under let next ... write let shot ...; in reset, under aim = ..., write
shot = null.reset, leave an empty line and write shoot.else return, and the pointerup line under the pointerdown line.draw, under the next bubble, draw the shot.Skills: Velocity and gravity, Keyboard and mouse input