diff --git a/Assets/Scripts/Generation/DungeonGenerator.cs b/Assets/Scripts/Generation/DungeonGenerator.cs index 643a9e6..88d7f99 100644 --- a/Assets/Scripts/Generation/DungeonGenerator.cs +++ b/Assets/Scripts/Generation/DungeonGenerator.cs @@ -123,24 +123,7 @@ public class DungeonGenerator { AddCurve(rooms2, ed); } - path = new GenRoom(); - foreach ( GenRoom r in rooms2 ) { - for ( int x1 = r.bounds.x; x1 < r.bounds.x + r.bounds.width; x1++ ) - for ( int y1 = r.bounds.y; y1 < r.bounds.y + r.bounds.height; y1++ ) { - Vector2Int pos1 = new Vector2Int(x1, y1); - if ( path.tiles.ContainsKey(pos1) ) - path.tiles[pos1] = Room.TileType.GROUND; - else - path.tiles.Add(pos1, Room.TileType.GROUND); - for ( int x2 = x1 - 1; x2 <= x1 + 1; x2++ ) - for ( int y2 = y1 - 1; y2 <= y1 + 1; y2++ ) { - if ( !path.tiles.ContainsKey(new Vector2Int(x2, y2)) ) - path.tiles.Add(new Vector2Int(x2, y2), Room.TileType.WALL); - } - } - if (r.AllDoors().Count > 0) - throw new NotSupportedException("Paths should not have any doors"); - } + HashSet allDoors = new HashSet(); foreach ( GenRoom r in rooms ) { for ( int x1 = r.bounds.x; x1 < r.bounds.x + r.bounds.width; x1++ ) for ( int y1 = r.bounds.y; y1 < r.bounds.y + r.bounds.height; y1++ ) { @@ -150,6 +133,7 @@ public class DungeonGenerator { for ( int y1 = r.bounds.y + 1; y1 < r.bounds.y + r.bounds.height - 1; y1++ ) { r.tiles[new Vector2Int(x1, y1)] = Room.TileType.GROUND; } + allDoors.UnionWith(r.AllDoors()); foreach ( Vector2Int v in r.AllDoors() ) { Debug.Log("Door: " + v); if ( !r.bounds.Contains(v) ) @@ -157,6 +141,29 @@ public class DungeonGenerator { else r.tiles[v] = Room.TileType.DOOR; } + } + + path = new GenRoom(); + foreach (GenRoom r in rooms2) + { + for (int x1 = r.bounds.x; x1 < r.bounds.x + r.bounds.width; x1++) + for (int y1 = r.bounds.y; y1 < r.bounds.y + r.bounds.height; y1++) + { + Vector2Int pos1 = new Vector2Int(x1, y1); + if (path.tiles.ContainsKey(pos1)) + path.tiles[pos1] = Room.TileType.GROUND; + else + path.tiles.Add(pos1, Room.TileType.GROUND); + for (int x2 = x1 - 1; x2 <= x1 + 1; x2++) + for (int y2 = y1 - 1; y2 <= y1 + 1; y2++) + { + Vector2Int pos2 = new Vector2Int(x2, y2); + if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2)) + path.tiles.Add(pos2, Room.TileType.WALL); + } + } + if (r.AllDoors().Count > 0) + throw new NotSupportedException("Paths should not have any doors"); } //foreach (GenRoom r in rooms) {