Spielerando

Enemy Wave Spawner

A wave spawner sends enemies in rounds. A break counts down, the enemies of the wave arrive one by one, and the next break starts once the player has cleared them. Each wave is bigger, only so many may be alive at once, and a wave that drags on cannot stop the game.

Also called: Wave spawner, Enemy waves, Horde mode, Round spawner.

A sturdy badger with a round lantern shield blows a horn on a stone bridge while small spiky creatures march out of a dark archway one by one, with more waiting as silhouettes inside.
Burrgate Vigil, an invented bridge-defence game. Invented game, image generated with AI.

Paste this to your AI

Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.

Add "Enemy Wave Spawner" to my game.

What it should do: Waves give a fight a rhythm of pressure and relief. The player gets time to breathe, spend and prepare, then faces a harder round, and the game can grow in difficulty without anyone placing enemies by hand.

Build it exactly as this state machine. First check that it fits my game, then build it like this:

```mermaid
stateDiagram-v2
  [*] --> resting
  resting: Break
  spawning: Enemies arriving
  fighting: Wave under way
  won: All waves cleared
  resting --> spawning: countdown is over
  spawning --> fighting: last enemy is in
  fighting --> resting: cleared or too slow
  fighting --> won: last wave cleared
  won --> [*]
```

Use these starting values:
- totalWaves: 5 waves
- firstWaveSize: 4 enemies
- sizeGrowth: 2 enemies
- restTime: 8 s
- spawnInterval: 0.6 s
- maxAlive: 12 enemies
- fightTimeout: 90 s

Watch out for these common mistakes:
- One enemy holds up the whole game: Tell your AI: give each wave a time limit. When it runs out, start the next break anyway, and keep counting the leftover enemy. For the last wave, make the game hunt the leftovers down or show where they are.
- The whole wave arrives in one moment: Tell your AI: let enemies arrive one at a time with a set time between them, and also cap how many may be alive at once.
- The pace depends on the frame rate: Tell your AI: when the timer runs out, keep the time that ran past and add it to the next wait. If a long tick covers two arrivals, create both.
- The next enemy comes in a rush when room opens: Tell your AI: while the limit holds the wave back, do not let the timer run into the past. Bring in one enemy as soon as there is room, then wait the normal time.
- The wave ends while enemies are still arriving: Tell your AI: a wave is only cleared when every enemy has arrived and none is alive.
- Leftovers add to the next wave: Tell your AI: keep one count of all living enemies and check the limit against it, whichever wave they belong to.
- More deaths reported than enemies: Tell your AI: never remove more enemies from the count than are alive.

Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP

What it does

Waves give a fight a rhythm of pressure and relief. The player gets time to breathe, spend and prepare, then faces a harder round, and the game can grow in difficulty without anyone placing enemies by hand.

How it runs, as a diagram

Everything it can be in, and what moves it on. Your AI builds from exactly this.

countdown is overlast enemy is incleared or too slowlast wave clearedBreakEnemies arrivingWave under wayAll waves cleared
How it runs, as a diagram
  • Break → Enemies arriving: countdown is over
  • Enemies arriving → Wave under way: last enemy is in
  • Wave under way → Break: cleared or too slow
  • Wave under way → All waves cleared: last wave cleared

Good starting values

ValueStart withWhat it changes
totalWaves5 wavesHow many waves there are. The game is won when the last one is cleared. Five is a short session; endless play needs a different ending.
firstWaveSize4 enemiesHow many enemies the first wave has. Small enough that a new player can win it without knowing the game yet.
sizeGrowth2 enemiesHow many enemies each wave adds to the one before. Zero makes every wave the same size, which suits games where the enemies themselves get tougher.
restTime8 sThe break before each wave. Long enough to collect, heal and rebuild, short enough that the player does not get bored.
spawnInterval0.6 sThe time between two enemies arriving. It is never zero, because a whole wave in one moment is a wall and not a trickle.
maxAlive12 enemiesThe most enemies alive at once. It keeps the screen readable and the game fast. It is never zero, because with no room no wave could ever start.
fightTimeout90 sAfter this long a wave stops holding up the next one. An enemy stuck behind a wall or hiding would otherwise stop the game for ever. The last wave has no limit: it must really be cleared.

What usually goes wrong

One enemy holds up the whole game

An enemy gets stuck behind a wall, falls out of reach or hides. The wave never counts as cleared, the break never starts and the player waits for nothing.

Fix: Tell your AI: give each wave a time limit. When it runs out, start the next break anyway, and keep counting the leftover enemy. For the last wave, make the game hunt the leftovers down or show where they are.

The whole wave arrives in one moment

The game creates every enemy of the wave on the same tick. The screen floods, the game stutters and the player cannot react.

Fix: Tell your AI: let enemies arrive one at a time with a set time between them, and also cap how many may be alive at once.

The pace depends on the frame rate

The game creates one enemy per tick when the timer runs out and throws away the time that ran past. On a slow device the waves arrive slower, on a fast one faster.

Fix: Tell your AI: when the timer runs out, keep the time that ran past and add it to the next wait. If a long tick covers two arrivals, create both.

The next enemy comes in a rush when room opens

The wave is full to the limit and its timer keeps running. When the player kills three enemies at once, all three waiting enemies arrive on the same tick.

Fix: Tell your AI: while the limit holds the wave back, do not let the timer run into the past. Bring in one enemy as soon as there is room, then wait the normal time.

The wave ends while enemies are still arriving

The player kills the first enemies faster than new ones arrive. The count of living enemies hits zero and the game thinks the wave is cleared, although half of it has not come in yet.

Fix: Tell your AI: a wave is only cleared when every enemy has arrived and none is alive.

Leftovers add to the next wave

An enemy left over from a timed-out wave is still alive when the next wave starts. If the game does not count it, the limit is passed and the screen holds more enemies than intended.

Fix: Tell your AI: keep one count of all living enemies and check the limit against it, whichever wave they belong to.

More deaths reported than enemies

One explosion reports the same enemy dying twice. The count of living enemies goes below zero, the wave looks cleared too early, and later checks go wrong.

Fix: Tell your AI: never remove more enemies from the count than are alive.

How to check it works

Works well with

Common questions

how do i add enemy waves to my game

Paste this: Add enemy waves. Start with a break of 8 seconds. Then send 4 enemies one by one, 0.6 seconds apart. When the player has killed all of them, start the next break, and make each wave 2 enemies bigger. No more than 12 may be alive at once. After the 5th wave is cleared, the player wins.

how fast should waves grow

Add a few enemies each wave and stop at a limit the screen can hold. Growth that is too steep makes wave 4 impossible and wave 3 boring. As a start, add about half of the first wave's size each time.

why does my wave never end

One enemy is stuck, hiding or out of reach, so the count never hits zero. Give every wave a time limit, and for the last one show the player where the leftover enemies are.

should the player be able to call the next wave early

It is a good extra: skipping the rest of the break can give a small bonus. Only allow it between waves, never while enemies are still arriving.

Where it comes from

We could not find a reliable origin for this one yet.

Where this mechanic comes from has not been researched yet.

Games are named only as references. Names and marks belong to their owners, and nothing here is endorsed by them.

What was checked

This is what separates the blueprint from a catalogue entry: the values on this page come from code that runs.

Your AI gets the code

Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it