Live Demo
Horde is a small survivors-like game written on KenseiECS and running in your browser on .NET WebAssembly. Move, the weapons fire on their own; the horde grows wave after wave until thousands of enemies chase you at once. The STRESS slider multiplies the spawn rate to push the world past 20,000 live entities, and the ECS inspector shows every system's time per frame.
Controls
| Action | Input |
|---|---|
| Start | Click the game, or press Enter / Space |
| Move | W A S D or arrow keys; on touch screens, drag anywhere for a virtual stick |
| Pick an upgrade on level-up | Click / tap a card, or press 1 2 3 |
| Pause | Esc or P |
| Restart after game over | Click / tap Restart, or press R / Enter |
| ECS inspector | ` or the ECS button: entity count, frame time, filters, pools and systems; untick a system to switch it off live |
| Push the ECS | STRESS slider in the inspector (×0.25 to ×25 spawn rate and enemy cap); God mode keeps you alive while you watch |
Weapons fire automatically: a bolt at the nearest enemy, orbiting blades and a periodic nova pulse once you pick them. Enemies drop XP gems; walking near pulls them in. Every level offers up to three different upgrades — damage, fire rate, extra projectiles, pierce, move speed, magnet radius, max HP, or a new weapon — and the panel under the health bar shows the level of each one you have taken. Recovery (heal 50%) only appears in the last slot once fewer than three upgrades are left to max; when everything is maxed, each level-up heals you without stopping the run.
What to look at
The game is 22 systems in two named phases of a SystemsRunner. Each one is short and shows one KenseiECS feature; the inspector lists them with their timings, and you can switch any of them off to see what it does. The sources are in Demo/Game/Systems/. For a guided tour of the code behind some of them, see Inside the Demo.
Simulation phase (sim)
Runs only while the game is playing. The systems sit in one inline group, gameplay; a level-up or game over pauses the run by switching that group off with SetActive, so the runner skips it and no system checks the game status.
| System | What it does | KenseiECS feature |
|---|---|---|
clock | Advances game time | The smallest possible system: a hand-written IRunSystem with no Init, a singleton read by ref |
player-move | Applies input to the player | Generated Init ([Inc] and [Pool] fields), GetSingleton<PlayerInput> |
spawner | Ramping waves, walls of fast enemies, elites | World.CreateEntity + Add outside iteration, a [Shared] config, a tag component (Heavy); a Swarm component whose filter runs the swarm loop only while a wall is being laid down |
grid | Rebuilds the spatial grid around the player; enemies left far behind reappear ahead | SharedData holding a mutable service object; filter plus direct pool reads and writes, zero allocations |
steer | Chase plus soft separation from neighbours | Reaching components by entity index through pools: sparse-set O(1) Get |
integrate | Moves everything that has a velocity | An owning Group<Position, Velocity>: the hot loop walks two aligned spans with no lookups |
bolt-fire | Fires bolts at the nearest enemy | CommandBuffer and PendingEntity: spawns are recorded during iteration and created on playback |
bolt-hit | Bolts hit enemies | EventBuffer<Hit> + world.AddEvent (several events per entity per frame); destroying the current entity inside foreach |
blades | Orbiting blades | A filter that starts matching the moment the upgrade adds BladeWeapon |
nova | Expanding ring that hits everything it crosses | Two filters in one system; an entity created through a CommandBuffer and destroyed in place |
contact | Contact damage, invulnerability frames | Singletons written by ref; a Hit event used purely as a knockback carrier; a Dead tag on the player when HP runs out |
knockback | Pushes light enemies back | An [Exc(Heavy)] filter; a second consumer of the same Hit events |
damage | Applies hits, marks the dead | Consuming a OneFrame EventBuffer<Hit>; adding the OneFrame Died to the entity being iterated |
loot | Drops gems and sparks, removes the enemy | CommandBuffer playback after the iteration; past the gem cap, XP is folded into existing gems through RawData |
magnet | Pulls gems to the player; gems left far behind are moved ahead | [Exc(Magnetized)]; adding Velocity moves a gem into the owning group; event entities for XpGained |
level-up | Collects XP, pauses and offers upgrades | Event entities destroyed by the OneFrame cleanup at the end of the gameplay group's run; an [Exc(Dead)] filter in place of a status check |
lifetime | Expires bolts and particles | Destroying the current entity during reverse iteration — see the iteration contract |
Render phase (render)
A second named runner that fills the sprite buffer the page draws. It keeps running while the gameplay group of sim is switched off, so the level-up screen still shows the frozen horde. Everything outside the camera is culled.
| System | KenseiECS feature |
|---|---|
render-gems | A separate named phase toggled independently of sim (nested runners) |
render-enemies | Linear iteration over a pool's dense RawData / RawEntities — no filter needed when one component already identifies the set |
render-projectiles | An [Any(Bolt, Blade, NovaRing)] filter |
render-particles | A filter over a tag component plus data components |
render-player | GetSingletonEntity |
Things to try
- Raise STRESS to ×20 with God mode on and watch the entity counter pass 20,000 (Max out is ×25, capped at 30,000 enemies).
steeris the most expensive system;gridandrender-enemiesfollow. - Switch off
integrate: the horde freezes, because nothing else moves positions. - Switch off
steer: enemies stop chasing and coast on their last velocity. Walk away andgridkeeps bringing the stragglers back ahead of you. - Switch off
knockback: tanks and elites never were affected (they areHeavy), now nothing is. - Switch off the whole
renderphase: the sprites disappear while the simulation and the camera keep going.
How it's built
- Plain .NET, no Unity. The game is a
net8.0class library (Demo/Game) referencing the sameKenseiECS.NETproject and source generator as any .NET app. A thin browser host (Demo/Web,Microsoft.NET.Sdk.WebAssembly,net10.0) callsHordeGame.Tickevery animation frame and draws the sprite buffer on a canvas. A headless runner (Demo/Headless) plays the same game in CI. - Built with
KENSEI_DEBUG. The deployed build definesKENSEI_DEBUG, so the per-system timings in the inspector are real (SystemInfo.LastRunMs/PeakRunMs) and stale-handle misuse would throw. A release build is somewhat faster. - Interpreted, single-threaded. The browser build runs on the .NET WebAssembly interpreter (no AOT, no
wasm-toolsworkload) — tens of times slower than desktop .NET, where a 10,000-enemy frame takes about 0.5 ms.Environment.ProcessorCountis 1 in the browser, so aParallelRunnerwould have no workers and run its jobs inline; the game does not use one. - No garbage in steady state. After warm-up a frame allocates nothing; allocations happen only when a pool, filter or buffer doubles its capacity.
- Small. The published site is about 4.5 MB (about 1.8 MB gzipped on the wire): the runtime, a trimmed BCL and the game, with no globalization data. KenseiECS and the game assembly are kept untrimmed (
TrimmerRootAssembly); only the BCL is trimmed.
