@2d-game-grid/square
Version:
A simple square grid made for games
13 lines (12 loc) • 530 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mapWalkableMatrix = mapWalkableMatrix;
/**
* Converts the grid into a matrix for the pathfinding lib
* @param grid The grid
* @param isWalkable A function that returns true, when the cell is walkable
* @returns A 2-dimensional array with a 0 for walkable cells and a 1 for not walkable cells (walls)
*/
function mapWalkableMatrix(grid, isWalkable) {
return grid.rows.map((row) => row.cells.map((cell) => (isWalkable(cell) ? 0 : 1)));
}