mwg API
    Preparing search index...

    Class Spawner<T>

    A dt-driven timer for escalating, timed spawning - "wave 3 starts at t+45s, spawns 8 of kind A and 2 of kind B over the next 10s" - distinct in shape from roguelike.Scheduler, which orders whose turn it is by energy cost and has no concept of real time at all. Not specific to tower defense: any game with escalating timed spawns (a horde mode, a survival minigame) wants the same primitive.

    The whole schedule is flattened and sorted once, at construction, rather than tracked wave by wave - simpler to get right, and cheap enough that a spawner is not something a game expects to have thousands of.

    import { Spawner } from '@datamoc/mw_games/core';

    const spawner = new Spawner<'rat' | 'bat'>({
    waves: [
    { delay: 0, entries: [{ kind: 'rat', count: 3 }], duration: 5 },
    { delay: 20, entries: [{ kind: 'rat', count: 5 }, { kind: 'bat', count: 2 }], duration: 10 },
    ],
    onSpawn: (kind) => console.log('spawn', kind),
    onWaveStart: (index) => console.log('wave', index, 'starting'),
    });

    // in the game loop:
    spawner.update(1 / 60);

    Type Parameters

    • T
    Index
    • get isComplete(): boolean

      true once every scheduled spawn has happened

      Returns boolean