mwg API
    Preparing search index...

    Class FreeMover

    Movement not snapped to any grid: a float position plus a continuous facing angle, for a twin-stick shooter, a bullet-hell, or any top-down game whose player moves and aims freely rather than stepping cell to cell. rpg.GridMover is the tile-to-tile counterpart to this; both own position and animation only, nothing about collision or passability.

    import { FreeMover } from '@datamoc/mw_games/rpg';
    import type { MovableSprite } from '@datamoc/mw_games/rpg';

    declare const heroSprite: MovableSprite;

    const mover = new FreeMover(heroSprite, 100, 100, { speed: 120 });

    // in the game loop, from a joystick or WASD:
    mover.move(1, 0, 1 / 60); // unnormalized direction; FreeMover normalizes it
    console.log(mover.facing); // radians, updated to face the movement direction
    Index
    facing: number = 0

    radians; unchanged while not moving, so a stopped unit keeps facing where it last went

    x: number
    y: number
    • Moves this frame along (dx, dy), which need not be normalized - only its direction and whether it is nonzero matter, so a caller can pass a raw stick reading straight through. (0, 0) stops the unit in place, facing whichever way it was last moving.

      Parameters

      • dx: number
      • dy: number
      • dt: number

      Returns void

    • faces a direction without moving, the free-movement equivalent of GridMover.turnTo

      Parameters

      • dx: number
      • dy: number

      Returns void