Workshop › Space Invaders-style › Step 5 of 21
Space fires a bullet from the cannon. Bullets live in a list, each a small box starting just above the ship.
```js
const BULLET_SPEED = 8
let bullets = []
function shoot() {
bullets.push({ x: ship.x + SHIP_W / 2 - 2, y: ship.y - 12, w: 4, h: 12 })
}
if (event.key === ' ') shoot()
```ship.x + SHIP_W / 2 - 2.shoot adds it to bullets; Space calls shoot.SHIP_SPEED, write BULLET_SPEED; under ship, write let bullets = [].keys, write shoot; in keydown, fire on Space.Skills: Keyboard and mouse input, Arrays and objects
← Stay on screen Bullets fly →