mwg API
    Preparing search index...

    Function rectsOverlap

    • Whether two rectangles overlap, optionally requiring margin cells of clearance between them - the check generateDungeon itself uses so rooms never end up sharing a wall.

      Parameters

      Returns boolean

      import { rectsOverlap } from '@datamoc/mw_games/roguelike';

      const roomA = { left: 0, top: 0, right: 4, bottom: 4 };
      const roomB = { left: 5, top: 0, right: 9, bottom: 4 };
      rectsOverlap(roomA, roomB); // false - adjacent, not overlapping
      rectsOverlap(roomA, roomB, 2); // true - too close with a 2-cell margin required