Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 2 min read

How we made a sled game whose leaderboard cannot be faked

Free game of the week: Sled Volt. It is a 3D downhill sled runner that runs in a browser tab. This is how it is built, and the one design decision that matters most if you ever want a leaderboard that people cannot fake.

Free game of the week: Sled Volt. It is a 3D downhill sled runner that runs in a browser tab. This is how it is built, and the one design decision that matters most if you ever want a leaderboard that people cannot fake.

The problem with browser leaderboards

If the game posts "I scored 90,000" to a server, anyone with dev tools can post 9,000,000. We did not want to ship a board full of impossible runs.

The fix: a deterministic simulation

Sled Volt's whole simulation runs on a fixed 60 Hz tick and uses only addition, subtraction, multiplication and division, so the same inputs give the same run on every device. The game records the inputs (lane changes, jumps, tucks, boosts) and posts those with the score. The server re-plays the run from its inputs and only ranks the score it gets itself. A made-up score fails because the re-play does not reach it.

The same rule is also why the Daily Run works: the course comes from the date, so every player gets the same mountain, and a friend's run can be re-played as a ghost beside yours.

Other choices that kept it small

  • Three lanes, three moves. Swipe left or right to change lanes, up to jump, down to tuck (a tuck is faster on the ground), double-tap for a boost. Inputs are buffered for a few ticks so a swipe a moment before landing still counts.
  • Telegraphed obstacles. Colour never changes meaning: red and orange means crash, yellow and black stripes mean jump, an orange flag means duck. Obstacles appear 2.4 seconds ahead at top speed, so a loss feels fair.
  • Restart in under half a second. After a crash, one tap restarts, because "one more try" is the whole game.
  • No install. It is a web page that works offline once loaded and can be added to a phone's home screen.

What I would do differently

Replaying on the server costs CPU, and a long run costs more. We cap run length and do the re-play where the time limit is generous. If you build the same thing, design the cap in from day one.

Play Sled Volt free in your browser: Sled Volt. Next week: another game and how it was made.

Published automatically by CyberMax. Every number above comes from the linked public data; nothing is estimated.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.