Own project, MIT licence
Stonefold: castle strategy
A strategy game in the browser, played on full-screen scenes as in the hero-led strategy games: the town, the map round it, the heroine’s sheet and the raid at the walls. You pick your heroine’s class (knight, mage or scout) and her looks, then grow a settlement round a keep for a few years. Each season you put villagers to work, place new buildings and lay the wall piece by piece on the town’s grid, and send the heroine out to mines, chests, shrines and relics. When a winter ends the raiders come up the field, each up one column of the grid, to the first piece of wall standing in it: where you built the wall, the gate and the towers is where the fighting is, and a column left open is an open door. Between waves you hire archers and spearmen onto the pieces, repair what broke and cast a spell. Every raid is announced from the first season and nothing is left to chance, so a lost keep tells you what to build differently. The first scenario walks a new player through it step by step.
Problem
An economy game with combat drifts apart between browsers easily: fractions and maths functions computed slightly differently by each engine give a different battle a few hundred steps later.
Balance tuned by feel gives a scenario that either everyone or no one wins. It needs a criterion that can be measured and held in tests.
Solution
The game engine touches neither the page nor browser storage and computes with integers only: fractions are stored in thousandths, and division and square roots go through its own functions. ESLint refuses division, fractional literals and most of Math in the engine, and a script replays sample seasons and raids in Node, Chromium and WebKit and compares the full state after every step.
A game is a list of decisions: assign, build, end the season, hire, repair, next wave, and the heroine’s level-ups, spells and rides. The page draws only what the engine rebuilds from it, and a save after every decision resumes the game after a reload.
Balance is held by two players who play through the same decision list as a person. The solver must win every scenario, and a careless player who picks random allowed moves must lose most of 200 runs.
- full-screen screens (title, creator, town, build menu, map, heroine, raid) drawn from sprites rendered by Blender scripts kept in the repo: flat colours in one palette, nature from Kenney’s CC0 Nature Kit recoloured to it, toy-like characters, the town’s grid drawn into the ground as tiles, buildings in four turns, the ground in four seasons
- castles built by hand on a grid, with a ghost to move and turn before it is built; three heroine classes as the game’s first decision; the solver wins every scenario with every class, careless play loses most runs, and no class is the only right one
- one camera for Blender and the page, so every sprite lines up by projecting its anchor; pan and pinch on a phone, mouse and keyboard on a desktop, English and Polish, tested in Chromium and WebKit
- TypeScript with no framework and no runtime dependencies; art by Blender (Python), WebP sprites
Try it
The application loads here as you scroll and needs JavaScript. You can also open it in a separate tab.
Stack
Repository
The repository is private for now; the code is available on request.
A similar problem on your side?
Tell us about it in a few clicks. You do not need a finished specification.
We usually reply within one business day. Prefer e-mail? Write to joanna@kokot.it.