UNPKG

@2d-game-grid/square

Version:
33 lines (32 loc) 919 B
import {ALL_DIRECTIONS, Neighbors} from '@2d-game-grid/core' /** * The representation of all neighbors of a cell */ export class SquareNeighbors extends Neighbors { /** * @param directions The allowed directions * @returns An array of all existing neighbor cell coordinates */ listCoordinates(directions = ALL_DIRECTIONS) { return super.listCoordinates(directions) } /** * @param directions The allowed directions * @returns An array of all existing neighbor cells */ list(directions = ALL_DIRECTIONS) { return super.list(directions) } getOffsetCoordinate(direction) { return { TOP_LEFT: {col: -1, row: -1}, TOP: {col: 0, row: -1}, TOP_RIGHT: {col: 1, row: -1}, RIGHT: {col: 1, row: 0}, BOTTOM_RIGHT: {col: 1, row: 1}, BOTTOM: {col: 0, row: 1}, BOTTOM_LEFT: {col: -1, row: 1}, LEFT: {col: -1, row: 0}, }[direction] } }