mwg API
    Preparing search index...

    Function ballistica

    • Traces a projectile-like path through a level and reports its first collision.

      Unlike traceLine, this understands the level topology and terrain. opaque is the default for beams and sight, impassable is useful for movement and projectiles that can cross transparent walls, and outside is useful when the requested target may be off-map. The collision cell is included in cells, so a caller can apply an impact there before deciding what the game should do with it.

      Parameters

      Returns BallisticaResult

      import { ballistica, Level, WALL, FLOOR } from '@datamoc/mw_games/roguelike';

      const level = new Level(10, 1, [WALL, FLOOR], 1);
      const result = ballistica(level, { x: 0, y: 0 }, { x: 9, y: 0 }, { stop: 'opaque' });
      console.log(result.cells, result.stop); // path and first blocking cell, if any