void GenerateBlank() { tileTypeMap = new int[width * height]; for (int i = 0; i < tileTypeMap.Length; i++) { if (tiles.Count == i) { tiles.Add(NewTile()); } else { tiles[i].gameObject.SetActive(true); } var typeOfTile = RoomMath.IndexOnPerimeter(i, width, height) ? TileType.Wall : TileType.None; tiles[i].transform.localPosition = GetTileLocalPosition(i); tiles[i].position = Coordinate.FromPosition(i, width); SetTileType(i, typeOfTile); } for (int i = tileTypeMap.Length, l = tiles.Count; i < l; i++) { tiles[i].gameObject.SetActive(false); } }
public static int StairsDownNextToGenerate(int roomWidth, int roomHeight) { if (_instance.roomHistory.Count == 0) { return(-1); } var refRoom = _instance.roomHistory[_instance.roomHistory.Count - 1]; var pos = RoomMath.GetCorrespondingPosition(refRoom, TileType.StairsUp, roomWidth, roomHeight, true); var coord = Coordinate.FromPosition(pos, roomWidth); if (RoomMath.CoordinateOnCorner(coord, roomWidth, roomHeight)) { if (coord.x == 0) { coord.x = 1; } else if (coord.y == 0) { coord.y = 1; } else { coord.x -= 1; } } return(coord.ToPosition(roomWidth, roomHeight)); }
public TileType GetTileTypeAt(Coordinate position) { if (RoomMath.CoordinateOnMap(position, width, height)) { return((TileType)tileTypeMap[position.ToPosition(width, height)]); } return(TileType.None); }
void SetDistanceMap(int source) { distanceMap = new int[tileTypeMap.Length]; highestDistance = -1; for (int i = 0; i < distanceMap.Length; i++) { distanceMap[i] = RoomMath.GetManhattanDistance(i, source, width); highestDistance = Mathf.Max(highestDistance, distanceMap[i]); } }
public void RequestMove(Coordinate target) { if (RoomMath.GetManhattanDistance(target, position) == 1 && target.Inside(roomWidth, roomHeight)) { moveTarget = target; queuedMove = true; } else { Debug.LogWarning(name + string.Format(" tried invalid move to {0},{1}", target.x, target.y)); } }
public static List <int> GetNonCornerPerimiterPositions(int width, int height) { var perimeter = new List <int>(); for (int i = 0, l = width * height; i < l; i++) { if (RoomMath.CoordinateOnNonCornerPerimeter(Coordinate.FromPosition(i, width), width, height)) { perimeter.Add(i); } } return(perimeter); }
public static List <int> GetPositionsAtDistance(int[] tileTypeMap, int origin, Range permissableDistance, TileType typeOfTile, bool requireStairsPosition, int width) { var matchingPositions = new List <int>(); int height = tileTypeMap.Length / width; for (int i = 0; i < tileTypeMap.Length; i++) { if (tileTypeMap[i] == (int)typeOfTile && (!requireStairsPosition || RoomMath.CoordinateOnNonCornerPerimeter(Coordinate.FromPosition(i, width), width, height)) && permissableDistance.Inside(RoomMath.GetManhattanDistance(origin, i, width))) { matchingPositions.Add(i); } } return(matchingPositions); }
List <int> GetNonPerimeterNeighbourIndices(List <int> indices, TileType neighbourType, int[] selector, int selectionValue) { var neighbours = new HashSet <int>(); for (int i = 0, j = indices.Count; i < j; i++) { var tileNeighbours = RoomSearch.GetNeighbourIndices(tileTypeMap, width, indices[i], neighbourType); for (int k = 0, l = tileNeighbours.Count; k < l; k++) { if (selector[tileNeighbours[k]] == selectionValue && !RoomMath.IndexOnPerimeter(tileNeighbours[k], width, height)) { neighbours.Add(tileNeighbours[k]); } } } return(new List <int>(neighbours)); }
public static List <int> GetNonPerimeterTilesThatBorderToType(int[] tileTypeMap, List <int> candidates, TileType borderType, int width) { var borderingTiles = new List <int>(); int height = tileTypeMap.Length / width; for (int i = 0, l = candidates.Count; i < l; i++) { if (GetNeighbourIndices(tileTypeMap, width, candidates[i], borderType).Count > 0 && !RoomMath.IndexOnPerimeter(candidates[i], width, height)) { borderingTiles.Add(candidates[i]); } } return(borderingTiles); }
Vector2 GetTileLocalPosition(int index) { var coord = RoomMath.GetTilePositionCentered(index, width, height); return(new Vector2(coord.x * tileSpacing.x, coord.y * tileSpacing.y)); }