Game development

Build an Asteroids-style movement model

An Asteroids-style ship points in one direction while its velocity can point in another. Store angle, velocity and position separately. Rotation changes the facing angle; thrust adds acceleration in that direction.

Wrap a position at the playfield edge by using a positive modulo expression. Give projectiles a lifetime and use a separate collision phase so removing an object cannot skip the next object in an iteration.

Split the project into four milestones: ship control, wrapping and projectiles, rocks and collisions, then score and restart. Test each milestone with simple shapes. Add screen shake and sound only after the rules are predictable.

Try the idea

ship.vx += Math.cos(ship.angle) * thrust * dt;
ship.vy += Math.sin(ship.angle) * thrust * dt;
ship.x = ((ship.x + ship.vx * dt) % width + width) % width;
ship.y = ((ship.y + ship.vy * dt) % height + height) % height;