cooperative/pvp tower defense game
  • C# 99.2%
  • HTML 0.4%
  • JavaScript 0.2%
  • Shell 0.1%
  • CSS 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-12 15:50:22 -04:00
.claude Headless testing setup 2026-10-08 16:59:27 -04:00
.config init repo 2026-10-08 16:49:06 -04:00
.vscode Wagonhold concept plan 2026-10-10 03:24:14 -04:00
capture Adds chat box to multiplayer 2026-10-12 15:50:22 -04:00
docs Wagonhold concept plan 2026-10-10 03:24:14 -04:00
instructions Adds chat box to multiplayer 2026-10-12 15:50:22 -04:00
src Adds chat box to multiplayer 2026-10-12 15:50:22 -04:00
tests/Wagonhold.Tests Adds chat box to multiplayer 2026-10-12 15:50:22 -04:00
.editorconfig init repo 2026-10-08 16:49:06 -04:00
.gitignore init repo 2026-10-08 16:49:06 -04:00
capture.sh Wagonhold concept plan 2026-10-10 03:24:14 -04:00
CLAUDE.md Wagonhold concept plan 2026-10-10 03:24:14 -04:00
PLAN.md New wagonhold MVP 2026-10-11 01:05:49 -04:00
README.md Adds chat box to multiplayer 2026-10-12 15:50:22 -04:00
run.sh Wagonhold concept plan 2026-10-10 03:24:14 -04:00
test.sh Wagonhold concept plan 2026-10-10 03:24:14 -04:00
Wagonhold.sln New wagonhold MVP 2026-10-11 01:05:49 -04:00

Wagonhold

An open world survival craft game built with C# on MonoGame for the desktop and KNI for the browser, from one codebase. You are a peasant hauling a single tower on a cart through a dark fantasy world: the tower is your home, weapon and workshop, and also your burden. By day you haul it and gather; at dusk you set it up for the night; at night the monsters come out of the dark.

Status: all seven milestones of PLAN.md are done: make your tower and peasant, walk a generated world hauling it, gather and craft, raise your tower storey by storey, set it up, survive the night, and do it with friends online. Further out are keeps to loot, shrines, raider camps, traders in the hamlets, and each biome's monsters and boss. Worlds and characters are saved. The main menu (Play, Multiplayer, Options, Quit) sits over a live world at nightfall.

Your tower is your character

Play opens your saved characters (or, the first time, the creator). A character is a level 0 tower and the peasant who hauls it, made like a D&D character in six steps, each with a live preview of the tower on its cart and a Random button:

  1. Calling, its class: the Ballista, Archers, Catapult or Brazier, which sets the weapon on top.
  2. Origin, what it was before the road, which sets its silhouette and two stat bonuses: a watchtower (its weapon reaches further), bell tower, mill, shrine, smithy chimney or lighthouse (the biggest light and most fuel).
  3. Stats, bought from 27 points between 8 and 15 as in D&D 5e: Masonry (walls and armour), Reach (range and attack), Flame (light and fuel), Heft (heavier to haul, but more room), Craft and Lore. The step shows what they come to.
  4. A virtue and a flaw: Old Stones, Haunted (a ghost guards it at night), Stout Axle, Deep Hearth or Lucky Stones; Leaning, Draughty, Heavy Timbers, Creaky or Restless.
  5. Its name and banner: a field, a division, a second tincture and a charge, seen by everyone.
  6. The peasant: a name, a build, a hood or hat, cloak and patch colours, a lantern, staff or satchel, and a knack (Strong Back, Forager, Tinker or Light Sleeper).

Characters are saved on this machine (as files in your local application data on the desktop, in IndexedDB in the browser); Delete on the list forgets one. A tower reaches level 1 when it sees its first night through, then levels on the D&D 5e XP table up to 20: each level brings hit points, proficiency rises at 5, 9, 13 and 17, each calling gains features at levels 2, 3 and 5, and at levels 4, 8, 12, 16 and 19 the tower gets +2 to a stat or a feat (press L when the prompt shows): Twin Bolts, Long Torch, Iron-shod Wheels, Thick Walls, Keen Watch, Quick Set, Deep Cellar or Steady Aim.

How to play

A new world starts with a random seed. You begin on the old road at the centre of the world, hitched to your tower's cart.

  • Walk with WASD or the arrow keys (gamepad: left stick or D-pad). Hitched to the cart, you haul it: fast on the cobbled road, slower on moss, slower still in mud and bog. Water and the fog past the world's edge can't be crossed.
  • E (gamepad A) uses what is nearest: take up or let go of the cart, or gather (fallen branches give timber, loose stones give stone, brambles give berries). Gathering takes a moment; walking off stops it.
  • Q (gamepad Y) sets your tower up for the night, or packs it away to move. Setting up and packing up take a few seconds, and you must let go of the cart first. Packed up, the tower's weapon is stowed and its torch dimmed; set up, it can't move, but its torch burns at full and its weapon fires at anything that comes near.
  • R (gamepad X) tends what is near: mends a damaged tower with stone or timber (scrap and iron later), or feeds its torch (or a campfire) with timber.
  • F (gamepad right shoulder) lights a campfire in front of you from two timber. A fire is light: nothing rises near it.

The day lasts 16 minutes, about 7 of them night. Light is safety: monsters rise only at night, only in the dark, and never near a player. Each has eyes and ears: a lit tower is seen from far off, a dark one only up close by a creature with darkvision, and the noise of hauling, gathering, building and firing carries. A monster that sees or hears a tower goes for it. Monsters attack towers, never peasants; the danger is losing the tower. A tower brought to 0 hit points is broken: its torch goes out, it can't fire, be set up or hauled until you mend it to a third of its hit points. Monsters left at dawn crumble away, and a tower that saw its first night through reaches level 1.

The HUD shows the day and hour, where you are, your tower (its walls, its torch's fuel, its armour, attack bonus and XP) and what you carry. The keys at the foot of the screen say what each would do now. Menu (or Escape, gamepad B/Back) returns to the main menu. F3 shows frame times.

Gather, craft, survive

The peasant carries a little in its pack (12 things, tools aside); the tower's store holds the rest (its size grows with Heft and Craft, and a mill holds more). Press I (Tab, gamepad Start) beside your tower to open the pack, the store and what its stations can make: click or Enter on a pack item stores it, on a store item takes it, on a recipe makes it (a few seconds of work); Store all empties the pack into the store.

  • Gathering with E: fallen branches, loose stones, brambles and pitch pools by hand; dead trees need an axe, rocks and iron ore a pick, flax a sickle. Nodes are spent as they are gathered; branches, brambles, flax and pitch grow back, felled trees after a long while, and quarried rock never. What has been gathered is stored and sent as changes to the generated world.
  • Stations live in the tower: every tower has a workbench (axe, pick, sickle, bolts, arrows, rope) and a hearth (stew, pit charcoal); a smithy chimney starts with a forge (iron from ore or scrap, iron bolts), a mill with a millstone (bread). Kilns come as modules.
  • Upkeep: the peasant grows hungry over a day and a half and tired over a day and a quarter, and slows down when either runs high. V eats the most filling food that won't go to waste, from the pack or (beside the tower) the store. T pitches a tent from 2 rope and 2 timber, rests in it (tiredness falls fast; walking gets up) or, from inside, gets up; E beside your tent takes it down. The tower's weapon spends ammunition from the store (bolts, arrows, stones, or a pitch pot every few bursts for the brazier) and falls silent without it; hauling over rough ground wears its walls a little; repairs take timber, stone, scrap or iron.
  • Saving: a single-player world saves itself every minute and when you leave, to your local application data on the desktop or IndexedDB in the browser. Play lists your worlds after you choose a character: carry on in one, or begin a new one (Delete forgets one). A hosted world saves the same way, and a dedicated server saves to the file given with --world.

Raise your tower

Press B beside your tower to raise it. Storeys are built between its origin's storey and its weapon top, each from its own makings: a storeroom (+30 store), a kiln (charcoal), a forge (iron), a loft (rest in the tower itself), a larder (food fills half again) and an armoury (+1 armour, +15 walls). A tower has one storey slot at level 2 and one more every four levels, up to four, but its chassis carries only so many: a handcart one, an oxcart two, a war wagon (+2 armour) four. Its crown can become a beacon (two fifths more light, more fuel) or a war banner (rallies towers near it, +1 to hit). Everything built adds weight, and so does a share of what the store holds: a heavier tower hauls slower. Taking a storey down gives half its makings back.

Draft animals: by day, wild donkeys and oxen wander the moor and the dead wood. Feed one berries (or bread) with E until it is yours; it follows you. E beside it, near your tower, yokes it (an ox needs an oxcart's yoke): it walks ahead of the cart and adds its strength, a donkey half again a peasant's, an ox nearly three.

The ground matters: slopes slow a cart going up and speed it a little going down (the ground is shaded where it rises and falls). In mud and bog a cart too heavy for what pulls it sticks fast until more hands push, an animal is yoked, or it is lightened. A Leaning tower hauled across a steep slope may topple, hurting its walls; E beside it rights it again.

Together on the road

Multiplayer plays with two to four players, desktop and browser mixed. Choose which of your characters to bring, then:

  • Join a world at its address (host, host:port, or a full ws:///wss:// address; the port is 5280 unless given). Browsers can only join; a page served over https joins with wss://, so a public server behind https needs a TLS certificate (or a proxy that has one).
  • Host a world (desktop only), a new one with a seed you type or a random one, or one of your saved worlds: the desktop serves it on port 5280 for others on the network and plays in it itself. Leaving closes it.
  • Or run a dedicated server: dotnet run --project src/Wagonhold.Server -- --port 5280 --seed 42 --players 4 --world myworld.bin (with --world it loads that file if it exists and saves to it every minute and on exit).

The server checks every joining character is legal (stats within the pool, names, known choices) and turns away one that isn't. A player who leaves and comes back under the same name takes up their tower where they left it.

Chat. In a world played with others, a log down the right of the screen shows what everyone says and who comes and goes; closed, its newest lines fade after ten seconds. Enter (or a click on the log) opens it to type a line; Enter says it to everyone and closes it, and Escape or a click elsewhere closes it, keeping the line for later. While it is open your peasant stands still, and Up/Down scroll back through the last hundred lines. A line is up to 100 characters of what the game's lettering can draw (letters, digits and . , : ! ? ' - / % + < >); the server cleans every line and holds back a player saying more than five in a burst or one a second after that. Single player has no chat.

On the road together, towers in mobile mode can be coupled into a train (C at the hitch of a tower standing behind another): the train follows its lead tower car by car, and is as heavy as all its towers. H beside a train someone is pulling pushes it, adding your strength; walk off to stop. Towers set up within a few tiles of each other make a wagon fort: overlapping fire and light, and +1 armour each for the cover. A bell tower rings at dusk to warn everyone near, and when set up rallies the towers around it (+1 to hit).

Combat: rough D&D

Every attack is a d20 to hit against armour class, then damage dice of a damage type, with resistance, vulnerability and immunity as in D&D 5e. A natural 20 always hits and rolls the damage dice twice; a natural 1 always misses, and a tower's weapon then takes twice as long to reload. Area weapons (the catapult's stone, the brazier's burst) use Dexterity saving throws for half damage, with natural 1s and 20s counting as crits too. Every die comes from the world's seeded random source, in integers, so fights replay exactly from a seed. Floating text shows each "Miss", each hit's damage and each crit.

A tower's stats work as D&D ability scores: Masonry gives its armour (10 + modifier) and hit points (the calling's hit die each level, times three: towers are buildings), Reach its attack bonus (proficiency + modifier), damage and range, Flame its light and fuel. The four callings are the Ballista (1d12, one target), Archers (1d8, twice a round, the longest reach), Catapult (2d8 in an area, every other round) and Brazier (2d6 fire around it). A D&D round is 3 game seconds.

Monsters are SRD creatures with their full stat blocks, 31 kinds from the bandit (challenge 1/8) to the pit fiend (20). Each biome has its own roster: bandits, goblins, wolves and hobgoblins on the moor; wolves, orcs, gnolls, dire wolves and the odd ogre in the dead wood; lizardfolk, ghouls, will-o'-wisps, ghasts, green hags and trolls in the bog; skeletons, zombies, wights, mummies and wraiths on the barrow downs; giants, red dragons and devils in the ash marches. Which kind rises is weighted by how far its challenge rating is above what the night readily brings, and that grows with each night and much faster with distance. Trolls regenerate unless fire or acid touched them that round; some attacks carry extra damage of a second type. A tower of the Shrine origin wards off the restless dead (none rise near it) and sears them for 2 more damage.

Felling a monster shares its XP among the towers that hurt it, by damage dealt. A tower takes a share that falls as it grows (WorldSim.XpShare), so level 20 takes about 200 hours of play; a model of a long run (XpPacing) checks that in a test.

Monster stat blocks are from the System Reference Document 5.1 by Wizards of the Coast LLC, available at https://dnd.wizards.com/resources/systems-reference-document, licensed under CC-BY-4.0.

The world

Worlds are 512 by 512 tiles of 40 units (configurable), generated in 16x16-tile chunks from a seed by integer hashing and value noise, so the same seed gives the same world on the desktop and in the browser (a test pins chunk hashes). Five biomes ring out from the start: moss moor, dead wood, bog, barrow downs and ash marches, each with its own ground (moss, leaf litter, peat bog, downs grass, ash, mud, stony ground and water) and scenery (rocks, dead trees, fallen branches, loose stones, brambles, flax, iron ore, pitch pools, ruined walls and barrows). An old cobbled road crosses the world west to east through the start, and roads wind out to hamlets in every ring. Only the changes to the ground (things gathered, grown back) are stored and sent; the rest comes back from the seed.

Further out (laid out from the seed, more of them in the far rings, never on a road):

  • Ruined keeps: broken walls round a court with a chest of silver and finds, more the further out.
  • Wayside shrines: pray there once a day (E) to ease hunger and tiredness and mend your tower by a quarter if it is near.
  • Quarries: stony ground thick with rock and iron ore.
  • Raider camps: a palisade round a chest, and a warband rising there at night when a player is near.
  • Lairs: each biome's boss rises at its lair once a night when a player comes within reach: the ogre on the moor, the ettin in the dead wood, a young black dragon in the bog, a mummy lord on the downs and a pit fiend in the ash marches.
  • Hamlets have traders (M to trade): bread, rope, iron, charcoal, pitch, ammunition, tools, a donkey or an ox for silver, and they buy what you gather.

Far from the start a warband may also rise around a player once a night.

Layout

Path What it is
src/Wagonhold.Core Pure game logic (no MonoGame/KNI); unit-tested. Sim is the world and its rules, Net the server, client and wire format, Ui the screens, Art the sprites.
src/Wagonhold The desktop game (MonoGame DesktopGL, .NET 9): Game1, rendering, input, sound.
src/Wagonhold.Server The dedicated server (ASP.NET Core, Kestrel), and the desktop's listen server: worlds served over WebSockets.
src/Wagonhold.Web The browser build (KNI BlazorGL, .NET 10). Compiles src/Wagonhold's sources; see instructions/web.md.
tests/Wagonhold.Tests xUnit tests.
capture/ Capture scripts: scripted input and screenshots from a hidden run of the game.
instructions/ Rules for working in this repo.
docs/ The archived tower defense plan.
PLAN.md What's done and what comes next, milestone by milestone.

Requirements

  • .NET 9 SDK (desktop game and tests) and .NET 10 SDK (browser build)
  • The wasm-tools workload for the browser build: dotnet workload install wasm-tools
  • MonoGame's content tools are local dotnet tools: dotnet tool restore

Build, run, test

./run.sh                                          # desktop (same as below)
dotnet run --project src/Wagonhold                # desktop
dotnet run --project src/Wagonhold.Web            # browser, http://localhost:5260
dotnet publish src/Wagonhold.Web -c Release -o dist-web   # browser release build (AOT), dist-web/wwwroot
./test.sh                                         # tests + browser build
./capture.sh capture/walk.txt                     # headless screenshots -> capture/out/
./capture.sh capture/night.txt --time 0.74 --day 240      # a whole night, quickly
dotnet run --project src/Wagonhold -- --sprites capture/out/sprites.png   # every sprite on one sheet

Controls

Where Input
Main menu Mouse to hover and click; Up/Down or W/S (gamepad D-pad) to move; Enter or Space (gamepad A) to choose.
Characters Up/Down or the pointer to pick; Enter or a click to play it or make a new one; Delete forgets the chosen one; Back or Escape returns.
Worlds As Characters: carry on in a saved world or begin a new one; Delete forgets one.
Creator Up/Down or the pointer to pick a row; Left/Right or the arrows to change it; type a name on a name row (Backspace erases); Random (Tab, gamepad X) rolls the step; Next or Enter goes on, Back or Escape goes back.
World WASD or arrows (left stick, D-pad) to walk; E (A) to take up or let go of the cart and to gather; R (X) to mend or refuel; Q (Y) to set up or pack up; F (right shoulder) to light a campfire; L (left shoulder) to spend a level-up; C (left stick) to couple or uncouple; H (right stick) to push a train; I or Tab (Start) for the pack, store and crafting; B to raise the tower; V to eat; T to pitch a tent, rest or get up; M to trade in a hamlet; in multiplayer, Enter to chat (Enter sends, Escape closes, Up/Down scroll the log). Menu or Escape (B/Back) returns to the main menu. F3 shows frame times.
Options Up/Down (or the pointer) to pick a row; Left/Right or the arrows to change it; Enter or a click flips a toggle. Back, or Escape (B/Back), returns to the menu.
Multiplayer Up/Down or the pointer to pick a row; Left/Right (or a click) changes the character; type the address or seed on their rows; Enter or a click joins or hosts; Back or Escape returns.

Quit closes the game on the desktop; the browser build leaves it out, since a tab cannot close itself, and leaves fullscreen to the browser. Escape never quits. The desktop window is resizable.

Art and sound

Flat vector dark fantasy: dusk, moss, wet cobbles and torchlight, muted colours with torch orange as the only accent. The rules, palette and scale are in instructions/art-style.md. All art is drawn in code, because the browser build has no content pipeline: Wagonhold.Core.Art holds a small anti-aliased vector rasteriser (Canvas, Shape with SVG path data), the palette (DarkFantasyPalette) and the sprites (DarkFantasyArt): ground tiles for every terrain with ragged edges over their neighbours, water with muddy banks, the cobbled road, scenery, the handcart in 16 headings with the tower riding on it and outriggers for defense mode, four tower callings in layers, the peasant (built from the monsters' figure parts, in homespun, with a lantern), 31 kinds of monster walking in every facing (upright figures, wolves and dragons on four legs, a wisp of light; each kind baked when it is first seen), chests, palisades and shrines, campfires, mist, and what a fight throws up: bolts, arrows, stones, splinters, dust, embers and fallen monsters. At night, Game1 draws a darkness layer with every light cut out of it as a hard-edged two-tone ring, then the torches' glow over it.

Text is set in DisplayFont, a serifed capital face defined as SVG path data (lower case as small capitals), baked at four sizes. The towers' shots are real CC0 recordings, several takes each, embedded in Wagonhold.Core as WAVs (Wagonhold.Core.Audio.SoundLibrary, which credits their sources) and played with a random take, pitch, volume and pan. The other sounds (hits, falls, a warning horn at nightfall and when a tower breaks, clicks) are synthesized in code (SoundSynth). Sound only starts after the first click or key press, as browsers require.

At start-up Game1 bakes everything a few milliseconds' worth a frame behind a loading screen, then packs it into one atlas texture. Wagonhold --sprites <file.png> [--only Peasant,Cart] [--scale 3] saves every sprite (or those whose labels start with the given words, enlarged) on one labelled sheet without opening a window.

How the game runs

Multiplayer is built in from the start (PLAN.md, Architecture). The world's rules all run in one WorldSim (Core, Sim), stepped at 60 Hz from each player's PlayerInput (a sequence number, the way they walk, the actions asked for). A GameServer (Core, Net) runs it: it reads inputs and sends each client a snapshot of what is near them 20 times a second, delta-encoded against the last snapshot that client acknowledged, in a hand-written binary format. A GameClient sends an input every step and predicts its own peasant and cart with the same Movement code the server runs, reconciling when a snapshot says where the server had them; everything else is drawn 100 ms behind, between snapshots. Chat goes alongside (protocol version 2): a client's Say goes to the server, which cleans it (Chat) and sends a Chat line to every player, with lines of its own when someone joins or leaves; WorldScreen.Chat (a ChatBox) keeps the log. Single player runs the server in the same process over a LoopbackNetwork, so there is one code path; tests run several clients over loopback with added latency and loss. Online, the transport is a WebSocket (WebSocketConnection, the same class on the desktop, in the browser and on the server): received messages wait in a queue drained once a frame, so nothing blocks or needs a thread on the web. Wagonhold.Server's ServerHost steps the world on one thread of its own and hands it connections through a queue.

The ground is a WorldMap: chunks generated from the seed by WorldGen (terrain, height, biome and nodes) when first needed and spread across frames, with the server's node changes laid over them. Bodies are circles that collide with scenery, water and each other; the cart follows its puller as a trailer (a rigid bar from axle to hitch). Wagonhold.Core.Ui holds the screens (ScreenFlow, MainMenu, WorldScreen, OptionsScreen, MenuBackdrop); Effects turns the world's events into splinters, embers, fallen monsters and floating text, and SoundCues into sounds. Game1 only draws what the client sees and reads input.

Headless captures

Wagonhold --capture <script.txt> [--out <dir>] [--stress] [--showcase [towers|far|hamlet]] [--seed <n>] [--time <0-1>] [--day <seconds>] (or ./capture.sh) runs the desktop game from a script of mouse, key, wait and screenshot commands, without showing a window, taking focus, reading the real mouse and keyboard, or making a sound, and saves PNGs (by default to out/ beside the script). Worlds in a capture come from seed 1234 unless --seed says otherwise; --time starts them at an hour (0 is midnight, 0.75 dusk) and --day shortens their days. capture/menu.txt walks the menus; capture/walk.txt hauls the tower along the road, off it and back; capture/edges.txt looks closely at terrain edges; capture/night.txt makes camp and holds a night until dawn; capture/creator.txt makes a character through every step and plays it; capture/host.txt hosts a world and plays in it; capture/chat.txt hosts one and talks in it; capture/join.txt joins a server (run two at once to see each other); capture/craft.txt stores, makes an axe and eats; ./capture.sh capture/showcase.txt --showcase shows towers raised every way; ./capture.sh capture/far.txt --showcase far a ruined keep and some of the bestiary; ./capture.sh capture/hamlet.txt --showcase hamlet a hamlet's trader; ./capture.sh capture/stress.txt --stress opens on a crowded night (four towers firing at sixty monsters that can't fall) and prints frame times (the browser build does the same with ?stress in the URL). The format is in instructions/capture.md.