How the game is put together

Every block of the code, how they talk, what I would change, what the next game can take. Tutorial left out. Hover or tap anything.

Next game takes it as isNo game words inside, or almost none. Next game takes it after a cleanupGeneral idea, some ties to this game. This game onlyWritten for Hollowtide. The next game writes its own.

The map

Three rooms, and they only talk through the arrows.

The brain: no Unity at all

Content files

Plain text files with every number in the game. No code. Change a price here and the game changes. Example: arrow tower costs 10 wood in buildings.json.
Buildingsbuildings.json: cost, health, range, recipes, sides that take and give.Enemies, unitsenemies.json and units.json: health, speed, weak spots.Waves, seasonsHow many monsters each night, how long days last.MapsOne file per map: water, rock, trees, rifts.

Game rules

This game's own rules, about 5,300 lines with the bot. They sit on top of the engine. A new game writes its own version of this layer.
Order desk706Sim.Commands: every order a player can give passes here, and each is answered yes or no with a reason. Check asks without doing, Apply does. Both use the same path, so the ghost can never lie. The idea moves to the next game, the orders do not.Content reader871Content.cs turns the text files into tables the engine reads. About half is general, half names this game's keys.Calendar, core622Sim.cs: day, dusk, night, seasons, waves, the core's level, win and lose.Hero345Walks, gathers, carries, shoots. He is one special unit of the engine with extra rules.Public view299State: a read only window on the sim. The screen looks through it, never touches.Bot1,399Plays the game alone for testing and balance. Holds 55 content names.

Engine

sim/Core, about 6,000 lines. Pure C# with no Unity and no game words. A test fails if the word hero or rift appears here. This is the treasure for the next game.
Base750Random numbers, ids, fixed size stores, event list, run fingerprint. Used by everything. Example: an id holds its slot and kind, so finding a thing is instant.Map, paths696Grid, flow field, crowd buckets, fog. Flow field: each cell stores which way to go, so 2,000 monsters share one map instead of each thinking alone.Tables355The shapes of kinds: EnemyKind, BuildingKind, recipes. Damage kinds are fixed in code: physical, fire, frost and so on.Fighting1,208Towers, units, enemies, shots, damage, burn, freeze. It names belts about 38 times: monsters smash or ignite them.Building911Placing, health, wrecks, walls, gates, what stands where.Factory1,569Belts, forks, merges, sockets, recipes, the pile. Almost free of fighting: it names fighting only 3 times.World hub532One tick in order. All blocks above are parts of one single class called World, 4,475 lines. This is the main thing to cut for reuse.
Photo
20 a second
After each tick, a copy of what the screen needs. Example: every enemy's position.
OrdersPlace a tower, move the hero. Orders queue up and run at the start of the next tick.BellsEvents: a shot was fired, something died. For sound and effects only.
The waiter

Bridge

The waiter between the sim and the screen, about 2,600 lines. The sim runs on its own thread on a computer, so the screen must never touch it directly.
Runner309SimRunner: 20 ticks a second, order queue, swaps the photos. No game word inside.Photo326RenderSnapshot: a copy of everything the screen needs, taken after each tick. So drawing never sees a half finished tick.Translator717RealSim: turns UI orders into sim orders, and fills the photo. One 250 line method.UI feed887UiGameBridge: fills the UI's state every frame. It still reads content a second time, 4 readers. This is the messy part.Replay log136RunLog and ReplayFile: every order with its tick, so any run can be played again exactly.
PhotoDrawing reads the photo directly.UI stateThe UI gets its own simple copy, once a frame.OrdersThe UI has one door: Send. It cannot reach anything else.
The screen: Unity

Controls

unity UI folder, about 8,300 lines. It references nothing, so it cannot touch the sim even by mistake.
Placement tool1,943Ghost, belts, walls, rows, stamp, take down, all in one class. 16 lines name game things. Old sim code still inside.Plan helpers476TilePlan, RowPlan, BlueprintPlan, GhostArrows, PileRate. No Unity logic, no game words, tested against the real sim.Bar, kit703BuildBar, UiKit, Ghost, ItemLines, BarKeys: general pieces, table driven.Map, top strip619Minimap, TopStrip, BuildingCard. A few game words.Panels1,250Hero controls, selection panels, admin. Full of this game.Main UI1,427HollowtideUI: runs the screen. 570 lines are a screenshot test script.

Drawing

unity World folder, about 5,000 lines. It reads only the photo. It cannot see the sim.
Draw kit1,787Crowd, belts, walls, buildings, terrain, fog, marks, health bars. Draws thousands of things cheaply. About 17 lines hold a game word in 1,787.Camera212Pan, turn, zoom, follow. 10 lines name game things.Feel hooks186Small signals for animations: an item arrived, a tower fired.Main drawing1,616WorldGame: which model is which, lights, effects. Seven jobs in one class.Hero, sound768HeroLook, TowerMotion, SoundPlayer: this game's looks.Start up471MainBoot: starts everything and plugs it together.

One tick

20 times a second, always in this order.

OrdersOrders that came in are applied first, in the order they arrived. So a list of orders is a replay. > HeroThe game layer moves the hero before the world steps. > SpawnMonsters due now come out of the rifts. > MakeCamps dig, makers cook recipes. > BeltsEvery item moves along its belt. > Who is whereCrowd buckets rebuilt: the map cut in squares, so looking around a tower is quick. > TowersPick a target, spend ammo, fire. > UnitsYour soldiers move and fight. > EnemiesRead the flow field, walk, attack. > ShotsArrows fly, land, hurt. > Clean upThe dead free their slots. > CalendarSight, core, day and night. > PhotoOne copy of it all goes to the screen.

One click

From your mouse to a tower on screen.

1MouseYou pick a tower and move over the map. PlacementTool snaps the ghost to a tile. > 2AskThe ghost asks: could it go here? The sim answers between ticks. Green or red. > 3ClickA PlaceBuilding order goes in the queue. A faint yellow shape shows at once. > 4Next tickThe order desk checks again, takes the wood, adds the building. > 5PhotoThe new building is in the next photo. > 6ScreenDrawing shows the model, the UI updates the pile. > 7BellAn event says built. Events only ring sound and effects, they never change play.

What I want to change

Proposal. Nothing done yet. No play change in any of them.

1One reader of content4 readersUI feed>0 readerssim tablesThe bridge reads the files again on its own. This caused the half size ghost circles. After: it asks the tables the sim already built. Removes about 150 lines. 2One trip for one fact7 stops>3 stopsAdding one fact to the screen means 7 edits today. After: 3. The start up copy CopyFrom goes, and sim answers use one function. 3Placement tool in five1 class23 old checks>5 toolsOne small class per tool: point, row, line, take down, stamp. Removes about 250 dead lines first. Each tool's flags die with it. 4Main classes cutWorldGame 7 jobsUI 570 test lines>1 job eachEffects, terrain and screenshots move out. No behaviour change. 5One idea of direction3 number systems>1 fileNorth is 0 in one, east is 0 in another. One small file, used everywhere. 6Cut World in parts1 class4,475 lines>5 partswith plugsThis is the key to reuse. Today you cannot take belts without fighting, since all are one class. After: each part stands alone and they meet through small plugs. 7Names leave the kitWords inside>Words in gameDamage kinds, camera and feel hooks hold this game's words. They move to tables the game fills.

Change 6, drawn

The one that makes reuse possible. Today all parts are one lump. After: parts that plug together.

TODAY World: one class, 4,475 lines FightingBuildingFactory Take one, you take all Base and map AFTER (PROPOSAL) Game rules pick the parts they want Fighting Building Factory Base and map Blue squares are plugsA plug is a small agreed question. Example: fighting asks what stands in this tile, and hits it. It no longer needs to know what a belt is. A game with no belts leaves that part out and everything else still works.

The kit for the next game

Proposal: ten modules. Each one can be picked up alone.

Base750 linesIds, random, events, fixed stores, fingerprint. Copy as is. Map and paths700 linesGrid, flow field, buckets, fog. Fighting1,200 linesUnits, enemies, shots, damage. Needs a plug instead of naming belts. Building900 linesPlacing, health, walls. Factory1,570 linesBelts, forks, recipes. Nearly free already. Sim host450 linesRunner, thread, photo swap, replay log. Draw kit1,790 linesThousands of things on screen, cheaply. Camera210 linesAfter 10 lines move out. UI kit3,800 linesBar, ghost, plans, placement tools, minimap. Test kittoolsHeadless runner, replay, two run fingerprint. Bot's general part. Not counted in lines.
Stays with Hollowtide
Game rules Content files Photo Translator Panels Main drawing Hero look Sounds
About 27,000 lines of code in all. As is: about 5,000. After cleanup: about 7,500. This game only: about 15,000. Lines are counted, the split between groups is my estimate. The 45 percent that moves holds the hardest code: paths, belts, drawing thousands of things.

45 percent of the lines, and the hardest ones. Tap the bar.

What each next game would take

Yes Some No
Another tower defense Live strategy Factory game Survival with a hero
BaseYesYesYesYes
Map and pathsYesYesYesYes
FightingYesYesNoYes
BuildingYesYesYesSome
FactorySomeSomeYesNo
Sim hostYesYesYesYes
Draw kitYesYesYesYes
CameraYesYesYesSome
UI kitYesSomeYesSome
Test kitYesYesYesYes

In what order

1
Tidy the bridgeabout 1 day, Safe during the jamChanges 1, 2, 5. Nothing a player can see. Makes the rest of the jam cheaper. Days are my guess.
one reader3 stopsone direction file
2
Split big classesabout 2 days, Safe after a buildChanges 3, 4. Each move is checked with a playtest. Days are my guess.
placement toolsWorldGamemain UI
3
Cut Worldabout 3 days, After 1 DecemberChange 6. Touches the sim's heart, so not during the jam. Same seed must give the same fingerprint before and after: that test already exists. Days are my guess.
5 partsplugstests per part
4
Make the kitabout 2 days, After 1 DecemberChange 7, then each module becomes a package. A tiny demo game proves nothing depends on Hollowtide. Days are my guess.
own repoUnity packagesa tiny demo game

Your call

1Tidy the bridge during the jam?YesNoOne day, no visible change.It is what you add to next that gets cheaper. Yes: a worker spends one day and adding things gets faster until 1 December. No: everything stays as it is and each new fact keeps costing 7 edits. My pick is yes. 2Cut World only after the jam?YesNoIt is the riskiest change.Yes: the sim stays stable until the deadline, and reuse waits until December. No: reuse comes sooner, but the core of the game is open during the last weeks. My pick is yes. 3Give the kit its own repo?YesNoEvery game then pulls from one place.Yes: a fix made in game two reaches game one. No: copy the folders each time, faster at first, and the copies drift apart. My pick is yes.
What this stands on