Ledge is a side-scrolling platformer. A small hooded hero runs, jumps twice, clings to walls and dashes through thirteen levels in five worlds: a meadow, a cavern, a foundry, a skyway drawn in 2.5D and the forge, where a golem waits at the end. Slimes, beetles, brutes, turrets, frogs and bats stand in the way, and coins, gems, keys, levers and crumbling floors fill the levels between them.
What sets it apart from a platformer you would write from scratch is that every run is recorded as the player’s input, one entry per tick, and the server plays that input back through the same engine to check the time and the score. That one property is what the leaderboards, the ghosts you race, the death heat map in the console and the level editor’s "can it be finished" check are all built on.
It shares the module layout and the accounts with Papercut and Skirmish. This chapter shows where each part lives and what to change to make the game yours.
Running it
The project is in scripts/ledge, and the Initializr generates it under your own
package and name. Start the server on the development profile, which keeps its
database in memory, seeds the demo accounts and simulates purchases:
CN1_PROFILE=dev backend/server.sh runThen run the app in the simulator, from the project’s directory:
mvn verify -Psimulator -DskipTests -Dcodename1.platform=javaseTo build the native iOS app on a Mac, generate the Xcode project, which lands under
ios/target, then open it and run it on a simulator or a device from Xcode:
mvn package -DskipTests -Dcodename1.platform=ios -Dcodename1.buildTarget=ios-source -Dopen=falseThe game plays without a server, and so does the editor; you only need one to sign
in, put runs on the boards, race other players and shop. Four demo accounts exist on
the development profile, each with the password ledge-demo:
| Account | What it’s for |
|---|---|
A player with five levels cleared and coins to spend. | |
A friend of the player, further ahead. | |
A player with a flagged run, so the console has something to review. | |
The administrator. |
A field of rivals with runs spread over this week and today is seeded too, along
with a set of runs that died on the way, so every board and the death heat map
have something on them. Outside the development profile only the admin is made,
and only when the ledge.admin.email and ledge.admin.password properties say
who.
What the sample does


The home screen plays a level by itself behind the menu, driven by the level’s recorded route. From there the world map leads to the levels, each unlocked by the one before it and scored with up to three stars for finishing, for beating the par time and for finding its gem. Today’s challenge is one level on the day’s seed, the same for every player, with a board of its own.
On a touch screen a joystick on the left moves and buttons on the right jump and dash; on a desktop the arrow keys or WASD move, Space jumps and Z dashes, and a gamepad works too. The skyway levels are drawn in 2.5D: the same level and the same simulation, rendered as blocks under a perspective camera that leans into the climb.


The boards show every level’s best runs for all time, the week, today and your friends. Every run on a board has two buttons: one plays it back, the other starts the level with that run beside you as a translucent ghost, and the HUD says how far ahead of you it is.


The modules
| Module | What it holds |
|---|---|
| The data transfer objects, the |
| The app: the level view and HUD, the touch controls, the menus and world map, the boards and races, the editor, the shop and the admin console. |
| The server: accounts, run tickets and replay verification, boards and ghosts, the daily seed, the shop, achievements, AI levels and administration. |
| The iOS build, for generating the Xcode project. |
The engine isn’t in the project. It’s Codename One’s own,
com.codename1.gaming.platformer, and the project depends on it like any other
part of the framework.
The engine: A simulation that replays
com.codename1.gaming.platformer is a character controller, a set of abilities
and a level model, in the spirit of the platformer kits other engines offer. Its
simulation half has no user interface at all and uses no floating point: positions
and speeds are 16.16 fixed point integers (Fx), the world steps exactly 60 times a
second, and its only randomness is a seeded generator (Rng). Given the same level,
the same seed and the same input, two runs end in the same state on every platform,
down to the last bit, and PlatformWorld.hash() proves it.
The pieces you work with:
TileGridandTile: the level’s collision map, written as rows of characters —#solid,=a one-way ledge,/and\slopes,Ha ladder,^spikes,~water.Actor, driven by an ordered list ofAbilityobjects:MoveAbility,JumpAbility(coyote time, a buffered press, variable height, double jumps),CrouchAbility,LadderAbility,WallJumpAbility,DashAbility, andJetpackAbility,GlideAbility,SwimAbilityandWeaponAbilityfor power-ups. A level names the hero’s abilities and tunes them.HitPoints,Checkpoint,Pickup,Door,Gate,Switch,Spring,CrumbleBlockandMovingPlatform: what a level is built of.AIBrain: the enemies' patrol, chase, shoot and jump behaviours.PlatformWorld: steps all that one tick fromInputbits.LevelData: reads a level from JSON and builds a world from it.InputLogandReplay: record a run’s input and replay it.
The presentation half is com.codename1.gaming.platformer.view: PlatformView
draws a world with parallax backgrounds, sprite animation, particles and screen
shake, interpolating between ticks; setDepth(true) draws it in 2.5D.
PlatformArt is the art it asks for, and Ledge’s LedgeArt is the one class in the
project that knows file names.
The engine’s simulation classes are marked to be shared with the backend, so the server compiles the identical code. That’s the whole trick behind the next section.
Scores the server can check
When a signed-in player starts a level, the server hands out a single-use ticket
with a seed. The app records every tick’s input in an InputLog while the player
plays, and sends the log, compressed as runs of equal input, when the level ends.
The server doesn’t trust the time or the score in that request: Scoring.replay
plays the log through a fresh world built from the same level and seed, and the
time, coins, deaths and score it stores are the replay’s. A run the replay doesn’t
finish is refused. A run too fast to be true, compared with the level’s own par
time, is stored and flagged for the console.
Because a stored run is only its seed and its input, it’s also a recording. Playing it back, racing it, and drawing where it died are all the same replay.
Writing levels
A level starts as a sketch in levels/src: a JSON header with its name, world, par
time and the hero’s abilities, a line holding only ---, then the level’s sixteen
rows of tiles with its things drawn in as letters:
{"name": "First Light", "theme": "meadow", "par": 40, "tuning": {"maxJumps": 2},S is the spawn and X the exit; o is a coin, * the gem, e a slime and
k a key. LevelSketch lists every letter. To add a level, compile its sketch,
have the solver prove it can be finished, and pack it:
python3 tools/sketch.py levels/src/2-4.sketch > levels/2-4.json
mvn -pl shared,backend -Dcodename1.platform=backend test -Dtest=LevelsTest -Dledge.record=2-4
python3 tools/pack-levels.pyThe solver (Solver, in shared) is a search over the real simulation: it tries
input patterns from the spawn, keeps the positions that got furthest, and stops
when the hero reaches the exit. The route it finds is written to
levels/demo/2-4.log only if it finishes the level on every test seed. That route is
what the home screen plays, what the tests replay to prove a level still works
after an engine change, and the first ghost a player races. tools/pack-levels.py
then writes every level and route into the LevelPack class, so the app and the
server replay the same bytes.
The level editor


The editor (EditorForm) edits the same sketch format on the device. Pick a tile or
a thing from the palette and paint; switch to pan to move around; change the world
or widen the level. Check runs the solver on a background thread and says whether
the level can be finished; Watch plays the solver’s route; Play tests the level
yourself. The level being edited is kept in storage between sessions.
Ask AI takes a description in words. Signed in, it goes to the server, which hands
it to a language model with a description of the sketch format, and runs the
solver on what comes back before returning it. A level the model drew badly, or
one the solver can’t finish, is replaced by one the built-in LevelGenerator
assembles from proven pieces, and a note says so. Offline, or with no model set
up, the generator answers directly. To set up a model, give the server a provider
and a key:
ledge.ai.provider=anthropic
ledge.ai.key=...The key stays on the server; the app never sees it. Requests are limited per player, and a description has a length limit.
The server


The backend is a Codename One backend application, and each area is a package:
account (sign-in, profiles, the demo accounts), run (tickets, replay
verification, boards, ghosts and the daily seed), shop (scarves, rewarded ads and
store receipts), progress (stars and achievements), friends, push, ai
and admin.
The console is part of the app, shown only to administrators, and the server limits every route
behind it to the ADMIN role in SecurityConfig. It shows today’s
numbers, finds players, reviews flagged runs, sets the daily seed, sends
broadcasts and keeps an audit of every action. Its Deaths tab is the heat map: the
server replays a level’s recent runs, those that finished and those that died on
the way, and counts the tile each death happened on. The place a level is too hard
shows up as a bright spot.
The art pipeline
Every picture and sound is made by tools/make-art.py, from shapes and synthesis:
five tile sets, the hero’s poses, seven enemies, items, three parallax layers per
world and nineteen sound effects. Nothing is downloaded or traced. Run it again
after changing a palette, a pose or an envelope:
python3 tools/make-art.py
python3 tools/make-art.py actorsTo use hand-drawn art instead, keep the file names and sizes that ART.md lists.
Making it yours
Levels: edit or add sketches, as in Writing levels.
The hero: a level’s header lists its abilities and tunes them (
maxJumps,jumpSpeed, run speed and the rest, onLevelData.applyTuning).A new enemy: a letter in
LevelSketch, a kind the engine’s brains can drive, and a sheet inmake-art.py.The look:
make-art.pyfor the art,common/src/main/css/theme.cssfor the menus.The shop: the scarves are a catalog in the backend’s
shoppackage.
Tests
mvn -pl shared,backend -Dcodename1.platform=backend test
./run-e2e.shThe server’s tests replay every level’s route on several seeds, have the solver finish every level from nothing, and check that each sketch still compiles to the level that ships, besides covering accounts, boards, the shop and the console. The end-to-end tests start the server and drive the app in the simulator: they play real levels by their routes, use the editor, race a ghost and open the console, and save a screenshot of each screen.