From c5aa4cdf5be668e4c605cb5832ede460a3b36dd9 Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Sun, 22 Apr 2018 20:37:16 +0200 Subject: [PATCH 1/2] Made doors visible --- Assets/Scripts/Door.cs | 4 ++-- Assets/Scripts/Generation/DungeonGenerator.cs | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/Door.cs b/Assets/Scripts/Door.cs index 9205fc9..ef5663e 100644 --- a/Assets/Scripts/Door.cs +++ b/Assets/Scripts/Door.cs @@ -39,7 +39,7 @@ public class Door : MonoBehaviour { locked = true; boundingBox.enabled = true; triggerBox.enabled = false; - GetComponent().enabled = true; + //GetComponent().enabled = true; } /// @@ -49,7 +49,7 @@ public class Door : MonoBehaviour { locked = false; boundingBox.enabled = false; triggerBox.enabled = true; - GetComponent().enabled = false; + //GetComponent().enabled = false; } /// diff --git a/Assets/Scripts/Generation/DungeonGenerator.cs b/Assets/Scripts/Generation/DungeonGenerator.cs index 48957b1..643a9e6 100644 --- a/Assets/Scripts/Generation/DungeonGenerator.cs +++ b/Assets/Scripts/Generation/DungeonGenerator.cs @@ -138,6 +138,8 @@ public class DungeonGenerator { path.tiles.Add(new Vector2Int(x2, y2), Room.TileType.WALL); } } + if (r.AllDoors().Count > 0) + throw new NotSupportedException("Paths should not have any doors"); } foreach ( GenRoom r in rooms ) { for ( int x1 = r.bounds.x; x1 < r.bounds.x + r.bounds.width; x1++ ) @@ -157,9 +159,9 @@ public class DungeonGenerator { } } - foreach ( GenRoom r in rooms ) { - generateInterior(r); - } + //foreach (GenRoom r in rooms) { + // generateInterior (r); + //} start = root.r; end = null; foreach ( GenRoom r in rooms ) { @@ -319,7 +321,8 @@ public class DungeonGenerator { if ( lower == lefter ) for ( int i = 0; i < TUNNEL_THICKNESS; i++ ) { lower.doorsRight.Add(new Vector2Int(horizontalLower.bounds.x - 1, horizontalLower.bounds.y + i)); - } else + } + else for ( int i = 0; i < TUNNEL_THICKNESS; i++ ) { lower.doorsLeft.Add(new Vector2Int(horizontalLower.bounds.x + horizontalLower.bounds.width, horizontalLower.bounds.y + i)); } @@ -329,7 +332,8 @@ public class DungeonGenerator { if ( lower == righter ) for ( int i = 0; i < TUNNEL_THICKNESS; i++ ) { higher.doorsRight.Add(new Vector2Int(horizontalHigher.bounds.x - 1, horizontalHigher.bounds.y + i)); - } else + } + else for ( int i = 0; i < TUNNEL_THICKNESS; i++ ) { higher.doorsLeft.Add(new Vector2Int(horizontalHigher.bounds.x + horizontalHigher.bounds.width, horizontalHigher.bounds.y + i)); } @@ -339,7 +343,8 @@ public class DungeonGenerator { if ( lower == lefter ) for ( int i = 0; i < TUNNEL_THICKNESS; i++ ) { lower.doorsDown.Add(new Vector2Int(verticalLefter.bounds.x + i, verticalLefter.bounds.y - 1)); - } else + } + else for ( int i = 0; i < TUNNEL_THICKNESS; i++ ) { higher.doorsUp.Add(new Vector2Int(verticalLefter.bounds.x + i, verticalLefter.bounds.y + verticalLefter.bounds.height)); } @@ -349,7 +354,8 @@ public class DungeonGenerator { if ( lower == righter ) for ( int i = 0; i < TUNNEL_THICKNESS; i++ ) { lower.doorsDown.Add(new Vector2Int(verticalRighter.bounds.x + i, verticalRighter.bounds.y - 1)); - } else + } + else for ( int i = 0; i < TUNNEL_THICKNESS; i++ ) { higher.doorsUp.Add(new Vector2Int(verticalRighter.bounds.x + i, verticalRighter.bounds.y + verticalRighter.bounds.height)); } From 59fbc56a5560ad40b73884bc56585ce8026a6e51 Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Sun, 22 Apr 2018 20:55:03 +0200 Subject: [PATCH 2/2] Fixed doors and wall generation --- Assets/Scripts/Generation/DungeonGenerator.cs | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) 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) {