Paper Plane: Throw It as Far as You Can

Loading...

Loading...
Paper Plane is a small browser game with one rule: throw the plane as far as you can. You fold your own plane from a sheet of A4, flick it off a hill, and your best distance goes on a shared leaderboard. Each go takes about ten seconds.
You can play it at plane.akli.dev.
I've always loved the Trials games, the 2D motorbike ones. What keeps me playing is how quick each attempt is. A run is short, you crash, you hit restart before you've even decided to, and the number you're chasing is right there. Ten minutes later you're still going, shaving tenths off a time you set yourself.
I wanted something on akli.dev with that loop. A game where you post a score and then someone else, or you tomorrow, tries to beat it. The site already had an Apps page full of small tools, but nothing you'd come back to just to play.
A good score-chasing game needs an idea you understand in one sentence. "Throw the plane as far as you can" is about as short as it gets. Nobody needs a tutorial for it.
The trouble with a pure throwing game is that it runs out of depth fast. Once you've found the perfect flick, you're done. The twist that keeps Paper Plane interesting is that you design the plane too.

In the Hangar you drag control points to shape the wing. The other side mirrors it. You choose how many times to fold the nose, how far to bend the elevator, and how much of each wingtip to fold up. Every plane comes from the same single sheet of A4, so a bigger wing means fewer nose folds. That paper budget is what makes it a trade-off rather than a race to the biggest wing.
Once the plane leaves your hand you have no control at all. The design and the throw are the whole skill. A heavy nose dives. A tail-heavy plane stalls and swoops. A light plane thrown too hard pitches up and drops out of the sky. You learn the physics by watching it go wrong, then tweaking one thing and throwing again. That's the Trials loop, just with paper.
I hid the numbers on purpose. You never see the exact angle or power of a throw, and there's no predicted flight path. You get an arm, an arrow and your judgement.
The game is three pieces across three repos, which matches how the rest of akli.dev is organised. The game and its physics live in vandelay87/paper-plane on GitHub.
core is the physics. It's pure TypeScript with no DOM or Node dependencies, published to npm as @akli-dev/paper-plane. It knows how to validate a design and fly it.web is the game itself: React 19, Vite and my own @akli-dev/ui components, deployed to S3 behind CloudFront.Both the browser and the Lambdas install the same core package. That one decision drives most of what follows.
A leaderboard that trusts the browser is a leaderboard someone will fill with 999,999 metre throws on day one. Anything the browser computes, a player can edit.
So the browser never sends a distance. It sends the design and the throw. The submit Lambda runs simulateFlight from the same core package and stores whatever distance it gets.
I considered the other options. Signing the score in the browser doesn't help, because anything the browser can sign, a player can sign too. Running the whole game on the server would make every throw wait on the network. A flight takes about 0.1 ms to simulate, so re-flying it on the server is nearly free.
Because the protection comes from re-flying rather than secrecy, I'm happy for the physics to be public on npm. It ships in the browser bundle anyway.
Re-flying only works if the browser and Lambda get exactly the same answer. Not close. Bit for bit. If your phone says 57.0 m and the server says 56.9 m, your genuine personal best gets scored differently from what you saw.
The first thing that breaks this is Math.sin. The ECMAScript spec lets engines approximate Math.sin, Math.cos and Math.atan2 however they like, so V8 on a server and JavaScriptCore on an iPhone are allowed to disagree in the last bit. Over a few thousand physics steps, one bit becomes a different landing spot.
So core brings its own trigonometry, built only from +, -, * and /, which IEEE 754 does guarantee:
export const sin = (x: number): number => {
const k = Math.round(x / HALF_PI)
const r = x - k * HALF_PI
const quadrant = ((k % 4) + 4) % 4
if (quadrant === 0) return sinKernel(r)
if (quadrant === 1) return cosKernel(r)
if (quadrant === 2) return -sinKernel(r)
return -cosKernel(r)
}It reduces the angle to a small range, then uses a Taylor series that's accurate to below 1e-16 there. The second thing that breaks determinism is frame rate. The simulation steps at a fixed 120 Hz no matter what the screen does, so a 60 Hz phone and a 144 Hz monitor run the same maths and just draw it at different speeds.
I knew I'd retune the physics after launch. I also knew that if retuning meant wiping the leaderboard, I'd never do it.
Two things make tuning safe. The first is a set of golden flights: fixed designs and throws, checked into the repo with their exact distances and flight paths. If any flight comes out differently, CI fails unless I've also bumped SIMULATION_VERSION. The physics can't change by accident.
The second is rescoring. The leaderboard stores each entry's design and throw, not just the distance. When I deploy a new version of core, a CDK Trigger re-flies every entry under the new physics and rewrites the distances. Everyone keeps their place, and the whole board stays measured by one set of rules. An old tab still running the previous physics gets a "please reload" message instead of a wrong score.
The throw is press, pull back, flick forward, release. The flick's direction sets the angle and its speed sets the power. This was the part I was least sure of, so I built a throwaway prototype first and tried it on a Pixel and a MacBook trackpad before writing the real thing.
The naive approach measures speed from the last two pointer events. That gives very different answers on a 60 Hz touchscreen and a 1000 Hz mouse. Instead, I fit a straight line through every pointer sample in the last 60 ms before release, and take its slope:
/** Least-squares slope of one coordinate against time, per ms. */
const slope = (samples: PointerSample[], key: 'x' | 'y'): number => {
const n = samples.length
const meanT = samples.reduce((sum, p) => sum + p.t, 0) / n
const meanV = samples.reduce((sum, p) => sum + p[key], 0) / n
let num = 0
let den = 0
for (const p of samples) {
num += (p.t - meanT) * (p[key] - meanV)
den += (p.t - meanT) ** 2
}
return den === 0 ? 0 : num / den
}The tests feed the same physical flick in at 60, 120 and 240 Hz and at mouse rates, and expect the same throw back. Power caps at 2,500 px/s, so a firm thumb and a fast mouse both reach 100%. A light plane thrown at full power stalls, so the best throw isn't always the hardest one.
There's also a keyboard throw: the arrow keys aim, and holding Space winds up a power meter. It needs the same kind of judgement as the flick, so neither input has an edge.

The game does what I set out to do, but there are three things I want to work on.
Weather. Every flight happens in the same calm air today. I modelled the conditions as data from the start, with wind and launch height passed into simulateFlight alongside the design and throw, so adding wind doesn't mean rewriting the physics. The fun part is deciding how it plays. A daily wind, the same for everyone, with its own daily leaderboard would give people a reason to come back each day and rethink their plane.
How it looks. The paper-craft style is all drawn in code on a canvas, with no image assets. It's clean, but it's plain. I'd like the world to feel more alive: a better sky, some scenery to fly past, and a plane that looks more like folded paper than a flat shape.
Playing on more than one device. There are no accounts. A player is a random ID in the browser's localStorage, which means you can play in one tap and I store nothing personal. The cost shows up as soon as you pick up a different device. Your phone and your laptop are two different players, so beating your score on the other one means posting a second entry on the leaderboard. Clearing your browser storage does the same. I'd like some kind of login, or a lighter way to link devices, so your personal best follows you. I'll need to work out how to do that without losing the "open it and throw" start that makes the game work.