mwg API
    Preparing search index...

    Class FieldOfView

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

    const level = new Level(20, 20, [WALL, FLOOR], 1);
    const fov = new FieldOfView(level);

    fov.update(5, 5, 8); // the hero's own sight, radius 8
    console.log(fov.visible.has(level.index(6, 5))); // true - lit right now
    console.log(fov.explored.has(level.index(6, 5))); // true - stays remembered after leaving
    Index
    explored: Set<number> = ...

    cells ever seen, which is what gets drawn dim

    light: Map<number, number> = ...

    how bright each visible cell is, 0 to 1, by cell index

    visible: Set<number> = ...

    cells currently in view

    • how lit a cell is right now, 0 when out of view

      Parameters

      • x: number
      • y: number

      Returns number

    • Recomputes what is visible from a point.

      Parameters

      • x: number
      • y: number
      • radius: number = ...

        how far light reaches, in cells. When omitted, the level's viewDistance is used, falling back to the larger level dimension.

      • Optionalsight: HeightSight

        when given, sight is height-aware: every cell in range is tested along the straight line to it, blocked by opaque terrain or by a cell rising above viewer and target alike. That is line-of-sight per cell rather than shadowcasting, so its edges deliberately disagree with the flat computation in the same way targeting already does - rot.js's callback only ever sees the blocking cell, never the target, so the viewer-relative rule cannot live inside it.

      Returns void