🏎️ CAR RACING

Dodge the traffic, overtake everything, and keep your foot down

← Back to Fun Time
Score
0
Metres
0
Level
1
Best
0

⌨️ Controls

  • steer between the lanes
  • accelerate   brake
  • W A S D work too
  • P or Space pause
  • R new race
  • Hold the keys — steering is not a tap!

🎯 How to play

  • Your car is the one with the racing stripe, at the bottom.
  • The road never stops. Steer between the three lanes to miss the traffic.
  • Every car you overtake scores points — and touching one ends the race.
  • Accelerating covers more road (and scores faster), but leaves you less time to react.
  • Every 5 cars passed is a new level, and every level is quicker.

🏆 Scoring

  • Each car overtaken is worth 10 × your level.
  • Metres counts how far you have driven — 10 pixels of road is 1 metre.
  • Level 1 rolls along at 180 pixels a second; level 11 screams past at 520.
  • However fast it gets, there is always 0.8 seconds between cars — just enough to swerve. 😅

🧑‍💻 For young coders: build this game yourself

This 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.