mwg API
    Preparing search index...

    Class MoveRouteRunner

    Drives a GridMover through a MoveRoute over successive update(dt) calls - the piece GridMover's own one-step-at-a-time moveBy/turnTo deliberately leaves out (see its own doc comment: whether a step is passable is the caller's question, not the mover's). Works against any GridMover, not only the player's - an NPC's wandering or patrol route is the same shape as a scripted cutscene walk.

    import { GridMover, MoveRouteRunner, type MoveRoute } from '@datamoc/mwg/rpg';
    import type { MovableSprite } from '@datamoc/mwg/rpg';

    declare const npcSprite: MovableSprite;
    declare function tilePassable(x: number, y: number): boolean;

    const mover = new GridMover(npcSprite, 3, 3, { tileWidth: 32, tileHeight: 32 });
    const patrol: MoveRoute = {
    steps: [{ dir: 'right' }, { dir: 'right' }, { wait: 1 }, { dir: 'left' }, { dir: 'left' }],
    repeat: true,
    };
    const route = new MoveRouteRunner(mover, patrol, {
    canMove: (dx, dy) => tilePassable(mover.x + dx, mover.y + dy),
    });

    // in the game loop:
    mover.update(1 / 60);
    route.update(1 / 60);
    Index
    • get done(): boolean

      true once a non-repeating route has run every step

      Returns boolean