Inside The Ninth Tower

An open-world action RPG for phones, where every sprite, tile, sound and note is made by code while the game runs. This page is built from that same code: everything that moves on it is the real thing.

Play the game Source on GitHub

Every pixel is a function

There's no art folder. A tree is a function that takes a seed and paints a canvas: a trunk, a canopy of shaded blobs, a lit top-left, a dark underside, and the ink outline every sprite shares. Change the seed and you get another tree from the same family.

Everything draws from one locked palette of 113 named colours. That keeps a goblin, a cottage and a lava field looking like they belong to the same world, and it lets the curse work as a single colour transform (more on that later).

Lives in src/gfx/: pixel.js has the shared tools (grids, outline, value noise, Bayer dither), props.js and creatures.js the scenery and monsters.

Heroes are puppets, dressed in gear

People aren't drawn frame by frame. A puppet renderer builds them from parts (head, torso, arms, legs) and poses them: a walk cycle, a sword swing, a cast, a dodge roll, a pickaxe swing. Gear is just more parts. Equip a different helm and the hero really wears it, in every frame.

Posing is too slow to do every frame, so the game bakes: when gear changes it renders every animation once into a single sprite sheet, and gameplay only ever draws one sprite per hero, however much they're wearing.

Try a different hero, a piece of gear, or an animation. The sheet below is the real bake: …

The world paints itself as you walk

Aldermere is one continuous map of 512 × 320 tiles. Painting all of it as pixels would take seconds and far too much memory on a phone, so it's cut into chunks of 256 pixels (16 × 16 tiles) and only the ones near the camera exist.

Each chunk is painted in a Web Worker, so walking never stutters. The worker builds its own copy of the world (it's deterministic) and only chunk coordinates cross the thread boundary; finished pixels come back as transferable buffers. Chunks beyond the unload radius are freed, and a hard cap of 40 throws out the farthest first.

Drag the camera across the map. The chunks you see are being painted for real, in a worker, on this page.

Loading means running generators

Since the art is code, "loading" is running a list of generator tasks. The core set (heroes, the common foes, trees, the font, the HUD) runs behind the first progress bar. Each region's art is its own group that loads only as you approach it.

Tasks run in 12 ms slices so the frame keeps rendering, and the game yields between slices with a MessageChannel, which browsers don't throttle the way they throttle timers in background tabs.

This runs the game's real asset list. Every tile below is a canvas one of the tasks just made.

Tap to walk

You steer the leader by tapping where to go. The game finds a route with A* on the tile grid (eight directions, no cutting corners past walls), then pulls the string tight: it drops every waypoint it can see past, so the hero walks in straight lines instead of zig-zagging tile to tile.

The other two heroes follow on their own. They take spots behind the leader, re-route around anything in the way, and file through doorways one at a time.

Tap anywhere in the village. Toggle the grid to see what's solid: water, walls, trees and the like.

Combat you can read

Fights are real time but deliberately legible. Every enemy swing has a windup you can see coming, and at most two foes wind up on one hero at the same time; the rest wait just outside reach. That one number, attackTokens, is the main dial for how hard a crowd feels.

Damage is simple to follow. A hit is your attack, times 1.75 if it crits, times any element or skill bonus, then cut by the target's defence. Plain attacks can miss (5% for most foes); skills always land. A hero who dodges gets a counter: their next hit within 3 seconds does 30% more.

Below: the real game in a sandbox you can play right here, then the token rule and the damage maths taken apart. Every enemy rule was added one at a time and measured with a fight benchmark before and after.

Dungeons are drawn in text

Every dungeon is a block of characters in dungeons.json. # is wall, B a push block, P a pressure plate, = a shutter, k a locked door, & lava. One shared kit turns the characters into rooms, doors, puzzles and fights, so a new dungeon is mostly writing a map.

Rooms are found by flood fill between walls and doors. A plate holds its shutter open only while something heavy sits on it, and a room counts as solved once stones cover all its plates.

This is the Forge of Ash's first room, straight from the data. Tap the block to push it.

When a Ward Stone falls

Each region starts under the curse: its colours drained toward a purple-grey, its music in a minor key. Breaking the region's Ward Stone sends a bloom of colour out across the land and the theme resolves to major.

Both halves are generated. The cursed land is the same painted terrain run through one palette transform. The cursed music is the same song: the sequencer maps every note to the parallel minor, so a composer only ever writes the hopeful version.

Break the stone. Sound on, if you like.

Music is data

Songs are written as data: tracks of [step, note, length, velocity] on a 16-step-per-bar grid, played by a small WebAudio synth with pulse waves, a triangle bass, noise drums, a pad, a bell and a generated reverb.

Tracks belong to layers. The base layer always plays; the combat layer (drums, a driving bass, a counter-melody) fades in when a fight starts. The sequencer schedules notes 150 ms ahead on a 25 ms timer, and skips voices whose layer is silent.

Pick a region's theme and play it. Turn the combat layer on and off while it runs.

Content is data too

Heroes, skills, gear, enemies, the world's people and every errand live in JSON. An errand is a giver, some dialogue and a list of steps (talk, gather, fight, escort, find), so adding a quest is writing data, not code. This matters beyond convenience: the same files are meant to carry over unchanged to a future native build.

Every character has a voice: a pitch, a wave shape and a speed. Dialogue plays a short blip per letter in that voice, and all text uses the game's own 3 × 5 pixel font.

A real errand from quests.json, played through the real font and voice.

Fitting in a phone

The budget is a mid-range phone in landscape. Most of the tricks are about doing work once, off the main thread, or not at all.

One rule covers a lot of it: nothing should cost more because the map is bigger. Per-frame work only touches what’s near you, and everything else waits, parked, until you come close. It’s checked on a generated map 40 times the size of the main one.

How changes are proven

Playtests find the bugs; scripts make sure they stay found. The test tools run inside the live game from the browser console: one plays every errand start to finish, one walks every dungeon to its boss, one checks that everything and everyone in a region can be reached on foot.

Speed is measured too. A profiler steps the game and times each frame, split into logic and drawing, on the main map and on the 40× map.

Combat changes are measured, not eyeballed. The old code runs twice first, to see how much the numbers wobble on their own, and only then the new code. Every bug that shipped once becomes a "never-again" rule in the design doc, with a check that catches it next time.

Come build something

New errands, townsfolk with odd curses, lore, balance, bigger ideas for the story or the world: all welcome, as long as they fit a warm, adventurous game that's generous to the player. Art and sound stay in code.