UNPKG

@2d-game-grid/square

Version:
26 lines (25 loc) 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listCellsInDistance = listCellsInDistance; const core_1 = require("@2d-game-grid/core"); /** * @param cell The start cell * @param maxDistance The maximum distance (including) to a cell that should be returned * @param algorithm The algorithm that should be used for the distance calculation * @returns All cells that are in the distance (excluding the start cell) */ function listCellsInDistance(cell, maxDistance, algorithm) { const queue = new core_1.UniqueCellQueue(); const neighbors = cell.neighbors.list(core_1.ALL_DIRECTIONS); queue.ignore(cell); queue.addAll(neighbors); const cellsInDistance = []; while (queue.hasNext()) { const nextCell = queue.getNext(); if (nextCell.getDistance(cell, algorithm) <= maxDistance) { cellsInDistance.push(nextCell); queue.addAll(nextCell.neighbors.list(core_1.ALL_DIRECTIONS)); } } return cellsInDistance; }