DEV Community

Pratyush Shivam
Pratyush Shivam

Posted on Originally published at pratyushshivam.com on

A game a five-year-old can play and an engineer can read

Cars following hand-drawn paths to coloured garages, from the game Junction

Junction: cars, vans and trucks drive into a yard from all four sides. With one finger you draw each one a path to the garage of its colour. Don't let them bump. You have three hearts. It starts calm.

What is under the hood

  • The whole game is a pure, deterministic simulation in TypeScript: no page, no clock, no Math.random. A round is three things, a seed, the shape of the field and the lines you draw, stepped at a fixed 60 steps a second. Same seed, same lines, same round, every time.
  • Today's round is seeded from the date. Every arrival takes exactly five numbers from a small seeded generator (Mulberry32): which edge, where along it, which vehicle, which garage, and the gap until the next. So everyone gets the same cars in the same order and can compare scores.
  • A line is just a list of points, thinned to one every 1.2 units. End it near the right garage and it snaps and locks. The vehicle walks the list at its own speed, and its body turns a little slower than its direction, which is what makes the steering look smooth.
  • Bumps are measured, not guessed. Every vehicle is a capsule, a line down its middle with half its width as the radius, and two touch when the distance between their lines is less than their two radii. Fifteen times a second the engine looks ahead along every line, six looks 0.3 s apart up to 1.8 s, and puts a "!" between any pair about to meet.
  • The difficulty is one formula: the gap between arrivals is max(1.4, 5.8 × 0.972ⁿ) seconds. Vans join at the third arrival, trucks at the tenth, pairs from the fifteenth. New garages open at 5, 13 and 24 delivered.
  • The yard is the same 16,000 square units on every screen, tall on a phone and wide on a laptop, so the traffic is just as dense either way.
  • Sound is made on the spot with WebAudio, one note per garage from a five-note scale, so any mix of deliveries sounds fine together. No audio files, no images.
  • Every garage has a colour and a shape, so the game never depends on telling two colours apart.
  • About 45 kB in total. 21 tests. No account, no server, no tracking.

Everything in the film is a real round, played with real pointer events, or drawn from the game's own code.

Play it: pratyushshivam.github.io/junction/

Source: github.com/pratyushshivam/junction

The film and the full write-up: https://www.pratyushshivam.com/projects/junction/

Top comments (0)