Workshop › Asteroids › Step 13 of 41
Space fires, once per press: holding the key sends repeated keydown events with event.repeat set, and we ignore
those. Each bullet is drawn as a small white square.
```js
if (event.key === ' ' && !event.repeat) shoot()
ctx.fillStyle = 'white'
for (const bullet of bullets) ctx.fillRect(bullet.x - 1.5, bullet.y - 1.5, 3, 3)
```' ' is the Space key; !event.repeat is true only for the first press, and && needs both.for (const bullet of bullets) goes through every bullet and paints a 3×3 square centered on it.keydown listener, under keys[event.key] = true, write the Space line.draw, under drawShip(), leave an empty line and write the two bullet lines.Skills: Keyboard and mouse input, Drawing on a canvas
← Making a bullet Bullets fly →