Workshop › Space Invaders-style › Step 6 of 21

Bullets fly

What we are doing

Every frame each bullet rises 8 pixels; bullets gone off the top are dropped. They are drawn white.

```js
for (const bullet of bullets) bullet.y -= BULLET_SPEED
bullets = bullets.filter((bullet) => bullet.y + bullet.h > 0)

ctx.fillStyle = '#f8fafc'
for (const bullet of bullets) ctx.fillRect(bullet.x, bullet.y, bullet.w, bullet.h)
```

What it means

Your turn

  1. At the end of update, move and filter the bullets.
  2. At the end of draw, draw them.

Skills: Velocity and gravity

All steps

  1. The ship
  2. The game loop
  3. Move the ship
  4. Stay on screen
  5. Fire
  6. Bullets fly
  7. A short reload
  8. The invaders
  9. The march
  10. Hit!
  11. Score
  12. They shoot back
  13. Bombs fall
  14. Lives
  15. Game over
  16. Best score
  17. A wave in a function
  18. Play again
  19. Waves
  20. Faster and faster
  21. Build it yourself: an extra life