Cyber Invaders: Space Grid · Step 2 of 4
Keyboard Strafe & Plasma Laser Weapon
In Step 2, connect keyboard event listeners to steer your defense ship left and right across the base perimeter, and fire glowing plasma laser bolts toward the sky when pressing Space or W!
What you will learn
- Horizontal Strafe Physics: Calculate horizontal movement using velocity vectors: ship.x += ship.vx. Clamp to screen boundaries.
- Projectile Spawning Pool: When space is pressed, push a new laser entity: { x: ship.x + width/2 - 2, y: ship.y, vy: -8 } into a lasers array.
Open this interactive lesson · Browse all lessons
In the editor, complete the marked TODOs. Use Stuck on a TODO? to reveal hints or a worked example, then run the lesson checks.