Dodge the traffic, overtake everything, and keep your foot down
← Back to Fun TimeThis game is not one big lump of code. It is split into five small library files inside the funtime/lib/ folder, and every single function has a comment above it saying exactly what goes in, what comes out, and the algorithm in plain English.
That means you can delete the body of any function, read its comment, and write it yourself — the rest of the game keeps working as soon as yours is correct.
| File | What it does | Good functions to try re-writing |
|---|---|---|
| lib/race-road.js | The road, the lanes and the shape of a car | laneCenterX, clamp, createCar, overlaps |
| lib/race-game.js | The rules: steering, traffic, crashing, scoring | steerPlayer, moveCars, keepCarsOnScreen, spawnCar, hasCrashed, updateRace |
| lib/race-draw.js | Painting the black-and-white picture | drawDashedLine, drawRoad, drawCar |
| lib/race-input.js | Keys you HOLD, and touch buttons | actionForKey, steeringFromInput, boostFromInput |
| lib/race-main.js | The glue between the page and the rules | updateScoreboard, gameLoop, connectKeyboard |
💡 The big idea: your car never actually moves forward. The traffic slides down the screen and the road markings scroll — that is the entire illusion of speed, and it lives in moveCars.
🛠️ Want to be walked through it? Build Car Racing Yourself takes you through twelve of these functions one step at a time, tests each one you write, and shows the game growing as you go.