Skip to content

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 ​

ActionInput
StartClick the game, or press Enter / Space
MoveW A S D or arrow keys; on touch screens, drag anywhere for a virtual stick
Pick an upgrade on level-upClick / tap a card, or press 1 2 3
PauseEsc or P
Restart after game overClick / 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 ECSSTRESS 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.

SystemWhat it doesKenseiECS feature
clockAdvances game timeThe smallest possible system: a hand-written IRunSystem with no Init, a singleton read by ref
player-moveApplies input to the playerGenerated Init ([Inc] and [Pool] fields), GetSingleton<PlayerInput>
spawnerRamping waves, walls of fast enemies, elitesWorld.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
gridRebuilds the spatial grid around the player; enemies left far behind reappear aheadSharedData holding a mutable service object; filter plus direct pool reads and writes, zero allocations
steerChase plus soft separation from neighboursReaching components by entity index through pools: sparse-set O(1) Get
integrateMoves everything that has a velocityAn owning Group<Position, Velocity>: the hot loop walks two aligned spans with no lookups
bolt-fireFires bolts at the nearest enemyCommandBuffer and PendingEntity: spawns are recorded during iteration and created on playback
bolt-hitBolts hit enemiesEventBuffer<Hit> + world.AddEvent (several events per entity per frame); destroying the current entity inside foreach
bladesOrbiting bladesA filter that starts matching the moment the upgrade adds BladeWeapon
novaExpanding ring that hits everything it crossesTwo filters in one system; an entity created through a CommandBuffer and destroyed in place
contactContact damage, invulnerability framesSingletons written by ref; a Hit event used purely as a knockback carrier; a Dead tag on the player when HP runs out
knockbackPushes light enemies backAn [Exc(Heavy)] filter; a second consumer of the same Hit events
damageApplies hits, marks the deadConsuming a OneFrame EventBuffer<Hit>; adding the OneFrame Died to the entity being iterated
lootDrops gems and sparks, removes the enemyCommandBuffer playback after the iteration; past the gem cap, XP is folded into existing gems through RawData
magnetPulls 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-upCollects XP, pauses and offers upgradesEvent 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
lifetimeExpires bolts and particlesDestroying 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.

SystemKenseiECS feature
render-gemsA separate named phase toggled independently of sim (nested runners)
render-enemiesLinear iteration over a pool's dense RawData / RawEntities — no filter needed when one component already identifies the set
render-projectilesAn [Any(Bolt, Blade, NovaRing)] filter
render-particlesA filter over a tag component plus data components
render-playerGetSingletonEntity

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). steer is the most expensive system; grid and render-enemies follow.
  • 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 and grid keeps bringing the stragglers back ahead of you.
  • Switch off knockback: tanks and elites never were affected (they are Heavy), now nothing is.
  • Switch off the whole render phase: the sprites disappear while the simulation and the camera keep going.

How it's built ​

  • Plain .NET, no Unity. The game is a net8.0 class library (Demo/Game) referencing the same KenseiECS.NET project and source generator as any .NET app. A thin browser host (Demo/Web, Microsoft.NET.Sdk.WebAssembly, net10.0) calls HordeGame.Tick every 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 defines KENSEI_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-tools workload) — tens of times slower than desktop .NET, where a 10,000-enemy frame takes about 0.5 ms. Environment.ProcessorCount is 1 in the browser, so a ParallelRunner would 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.