neighbors method

List<T> neighbors(
  1. int x,
  2. int y
)

Get all of the cardinal neighbors of the tile at column x row y.

Implementation

List<T> neighbors(int x, int y) {
  var neighbors = <T>[];
  var start = Vec2(x, y);

  for (var d in Direction.cardinals) {
    var neigbor = start + d;
    if (_tiles.isValid(neigbor)) {
      neighbors.add(this[neigbor]);
    }
  }

  return neighbors;
}