public Tile(Coord _RawCoord, Coord _Coord, Enums.tileType _tileType = Enums.tileType.Wall, int _RoomID = -1) { RawCoord = _RawCoord; Coord = _Coord; tileType = _tileType; RoomID = _RoomID; }
Tile GetNearestTile(int startX, int startY, Enums.tileType tileType, Tile[,] Map) { Tile NearestTile = Map[startX, startY]; int[,] mapFlags = new int[Map.GetLength(0), Map.GetLength(1)]; Queue <Tile> queue = new Queue <Tile>(); queue.Enqueue(Map[startX, startY]); mapFlags[startX, startY] = 1; while (queue.Count > 0) { Tile tile = queue.Dequeue(); for (int x = tile.RawCoord.coords.x - 1; x <= tile.RawCoord.coords.x + 1; x++) { for (int y = tile.RawCoord.coords.y - 1; y <= tile.RawCoord.coords.y + 1; y++) { if (IsInMapRange(x, y, Map) && (y == tile.RawCoord.coords.y || x == tile.RawCoord.coords.x)) { if (mapFlags[x, y] == 0) { if (Map[x, y].tileType != tileType) { mapFlags[x, y] = 1; queue.Enqueue(Map[x, y]); } else { NearestTile = tile; while (queue.Count > 0) { queue.Clear(); } } } } } } } return(NearestTile); }
List <Tile> GetFloorTiles(Vector2Int start, Tile[,] Map, int _RoomID = -1) { bool isColiding = false; List <Tile> tiles = new List <Tile>(); int[,] mapFlags = new int[Map.GetLength(0), Map.GetLength(1)]; Enums.tileType tileType = Enums.tileType.Floor; Queue <Tile> queue = new Queue <Tile>(); queue.Enqueue(Map[start.x, start.y]); mapFlags[start.x, start.y] = 1; while (queue.Count > 0) { Tile tile = queue.Dequeue(); if (tile.RoomID == -1 || tile.RoomID == _RoomID) { tiles.Add(tile); } else { isColiding = true; } if (!isColiding) { for (int x = tile.RawCoord.coords.x - 1; x <= tile.RawCoord.coords.x + 1; x++) { for (int y = tile.RawCoord.coords.y - 1; y <= tile.RawCoord.coords.y + 1; y++) { if (IsInMapRange(x, y, Map) && (y == tile.RawCoord.coords.y || x == tile.RawCoord.coords.x)) { if (mapFlags[x, y] == 0 && Map[x, y].tileType == tileType) { mapFlags[x, y] = 1; Debug.Log(Map[x, y].RoomID); if (Map[x, y].RoomID == -1 || Map[x, y].RoomID == _RoomID) { queue.Enqueue(Map[x, y]); } else { Debug.Log("Tile Coliding:" + tile.RawCoord.coords); isColiding = true; queue.Clear(); break; } } } } } } else { queue.Clear(); break; } } if (isColiding) { return(new List <Tile>()); } else { return(tiles); } }