/// <summary> /// Returns 8 sorrounding cells + the center cell of type 'Wall'. /// May return fewer if the cellIndex is near the sides/corners of the arena. /// </summary> /// <param name="cellIndex">(x,y) indices of the center cells</param> /// <returns></returns> IEnumerable <Vector2> GetSurroundingWallCellsCenters(Arena.Coords cell, Arena a) { for (int yDelta = -1; yDelta <= 1; ++yDelta) { for (int xDelta = -1; xDelta <= 1; ++xDelta) { int x = cell.x + xDelta; int y = cell.y + yDelta; if (x >= 0 && y >= 0 && x < a.Size && y < a.Size && a[x, y] == Arena.CellType.wall) { yield return(CalcPosFromCellCords(new Arena.Coords(x, y), a)); } } } }
static Vector2 CalcPosFromCellCords(Arena.Coords coords, Arena a) { return(Arena.origin + new Vector2(coords.x, coords.y) * Arena.offset * Arena.boundingBox); }