Turn, thrust, shoot — and remember that space has no brakes
← Back to Fun TimeThis game is split into small library files inside funtime/lib/, and every function has a comment saying exactly what goes in, what comes out, and the algorithm in plain English. Empty any function out, read its comment, and write it yourself.
| File | What it does | Good functions to try re-writing |
|---|---|---|
| lib/asteroids-rules.js | The rules: angles, drifting, wrapping, breaking | pointFrom, wrapPosition, thrustShip, hitRocks |
| lib/asteroids-draw.js | Painting the ship and the lumpy rocks | drawShip, drawRock, renderGame |
| lib/asteroids-main.js | The glue: the held keys, the taps, the loop | doAction, holdButton, gameLoop |
💡 The big idea: cos and sin turn a direction into a place. Give them an angle and a distance and they tell you exactly where you end up. Learn that one function and you can point, aim, orbit and steer in any game you ever write.
🛠️ Want to be walked through it? Build Asteroids Yourself takes you through the key functions one step at a time and tests each one you write. There is a Python version too.