
Every online leaderboard has the same problem. The client says “I finished in 41 seconds” and the server has to take its word for it. Within a week the top ten is full of zeros.
The fix is old and well known: don’t send the score, send the inputs, and let the server play the run again. It only works if both machines get exactly the same answer from the same inputs, on every frame, for minutes at a time. That’s the hard part. So we built an engine where it’s guaranteed. A replay proves a run is possible inside the rules: no edited score, no wall clipping, no speed hack. It can’t prove a human played it, and neither can anyone else’s.
Download the Hollowdeep video.
Why there are no floats
Floating point math isn’t the same everywhere. A compiler can fuse a multiplication and an addition into one instruction with different rounding. x87, SSE and ARM disagree about intermediate precision. In JavaScript every number is a double. Each difference is one bit in the last place, and a platformer amplifies it: a jump that lands one hundred-thousandth of a pixel lower catches a ledge on one machine and misses it on the other. A few hundred frames later the two runs are in different rooms.
com.codename1.gaming.platformer doesn’t use float or double anywhere in the simulation. Positions and speeds are 16.16 fixed point integers, Fx. Integer math gives the same answer on an iPhone, an Android tablet, a Windows desktop, a browser and a Linux server.
int speed = Fx.ratio(3, 2); // 1.5 pixels a tick
int pos = Fx.of(64); // 64 pixels
pos += Fx.mul(speed, Fx.of(10)); // ten ticks later: 79 pixels
int pixels = Fx.floor(pos);The rest of determinism is discipline. The world steps at a fixed 60 ticks per second whatever the frame rate. There’s no clock, and no Math.random: randomness comes from a seeded Rng. The view interpolates between ticks for smooth drawing, but drawing never feeds back into the simulation.
fixed point, 60 Hz"] B --> L[InputLog] S --> V[PlatformView
2D or 2.5D] L -->|upload| R["Replay.run()
same source on the server"] R --> Q{ticks match?} Q -->|yes| LB[Leaderboard] Q -->|no| X[Rejected]
A run is a few kilobytes
Input is ten bits per tick: left, right, up, down, jump, run, dash, fire, activate, and alt. Because the world is deterministic, the whole run is those bits and nothing else. An InputLog stores them and encodes them as compact text for upload.
The simulation classes are marked @SharedWithBackend, so the server compiles the exact same source as the app. Verifying a run is four lines:
LevelData level = LevelData.parse(levelJson);
InputLog log = InputLog.decode(upload, 60 * 60 * 15);
Replay.Result r = Replay.run(level, seed, log);
boolean genuine = r.isComplete() && r.getTicks() == claimedTicks;The same log drives a ghost. addGhost runs a second world from a recorded run and draws its hero faded over yours, so racing the world record is racing the actual world record, not an animation somebody faked.
Download the ghost race video.
A level is text you can read
Here’s level 1-2 of Ledge, “Ladder Hill”, trimmed to nine of its sixteen rows and the first 70 of its 134 columns:
{
"name": "Ladder Hill",
"theme": "meadow",
"par": 55,
"tuning": {"maxJumps": 2},
"abilities": ["move", "ladder", "walljump", "jump", "crouch", "dash"],
"spawn": [7, 10],
"goal": [119, 3, 1, 2],
"tiles": [
"..........................................=========...................",
"......................................................................",
".....................................H.................H..............",
".........................=======.....H.................H..............",
".....................................H#################H.........=====",
"................=====................H.................H.............#",
"...............................=========.........=========............",
"######################.......##########.............########..........",
"######################^^^^^^^##########.............########^^^^^^^^##"
],
"entities": [{"type": "coin", "at": [45, 1]}, ...]
}# is solid ground, = is a one-way platform you can jump up through, H is a ladder, ^ is a hazard, / and \ are slopes, and ~ is water. You can see the level before you run it. You can diff it in a pull request. And you can ask a language model to write one, because it’s text, which is exactly what Ledge’s on-device editor does when a model is configured.
The solver proves a level can be finished
A generated level, or one a player drew on the bus, might be impossible. Solver searches for an input log that reaches the goal, keeping the shortest input to every place the hero has reached and exploring outward from the places nearest the goal.
Solver solver = new Solver(level, 42L, 7L);
solver.setMaxTicks(60 * 120);
InputLog run = solver.solve(2000000L); // null when no path was foundLedge won’t publish a level until the solver finishes it. The four gallery games ship demo runs found this way, and a test plays every demo to the end, so a level edit that breaks a jump fails the build.
Download the level editor video.
2D, or 2.5D with the same level
PlatformView draws the same simulation flat or with depth: parallax layers, tiles extruded into blocks and a glTF model for the hero. The level and the physics don’t change, only the camera.
Download the 2D and 2.5D video.
Art comes in through importers: sprite sheets, Tiled maps and glTF models.
Download the Tiled import video.
Why a second game engine?
Codename One already has com.codename1.gaming: a game loop, sprites, scenes, Box2D physics and the Game Builder’s level model, GameLevel. That API is general. It drives a puzzle game, a top-down shooter or a physics toy, and it uses floats and decimal positions because Box2D does and because authoring tools think in decimals.
The platformer engine overlaps with it on purpose, in exactly one place: both can describe a level. They don’t share a base class, and that’s deliberate. A GameLevel is authoring data for any game, with sprites at decimal positions. A platformer LevelData feeds a simulation the server must replay exactly, so it holds whole tiles with collision meaning, fixed point numbers, and no images at all. A base class that served both would hold neither. Instead GameLevelImport converts one to the other when the level loads: you name which painted assets are ground, platforms and ladders, and which elements are the spawn, the goal and the coins.
So use com.codename1.gaming when you want physics and freedom. Use the platformer engine when the genre is a side scroller and you want the server to trust the result. Many games will use both: the platformer for the run, the gaming API for the menus and the boss fight cutscene.
Four games, every device
The gallery in scripts/platformer-gallery has four games built on the engine, each running on phone, tablet, desktop and web:
- Hollowdeep: exploration through connected rooms, with a minimap.
- Skyline Sprint: a one button portrait runner through a seeded city.
- Cliffside: 2.5D with a glTF knight.
- Crate Duo: a two player puzzle.
Download the Cliffside video.
Download the Skyline Sprint video.
Ledge: the game and the server
Ledge is the full template in the Initializr, MIT-0 licensed. Thirteen levels across five worlds, a hooded hero who double jumps, wall jumps and dashes past slimes, beetles, turrets and bats to a forge golem. Around the game is what a live game needs: accounts, all time, weekly, daily and friends boards, a daily challenge, a shop, achievements, push broadcasts, and a console that draws a heat map of where players die, computed from the server’s own replays.
The game, the scoring and the solver live in one shared module that both the app and the server compile. One language, one project, one source of truth for what counts as a legitimate run.
Generate Ledge from the Initializr, and read Building Platformer Games in the developer guide. Tomorrow: turning design files into forms.