From 336b57ae4e9f27d4bfe88bf2cf7383c4772a3ca5 Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Mon, 23 Apr 2018 00:27:44 +0200 Subject: [PATCH] Even better walls --- Assets/Scripts/Generation/DungeonGenerator.cs | 48 +++++++++++++------ Assets/Scripts/Generation/GenTile.cs | 12 ++--- .../Scripts/Generation/GenerationProcessor.cs | 14 +++--- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/Assets/Scripts/Generation/DungeonGenerator.cs b/Assets/Scripts/Generation/DungeonGenerator.cs index 85adea8..0d11e41 100644 --- a/Assets/Scripts/Generation/DungeonGenerator.cs +++ b/Assets/Scripts/Generation/DungeonGenerator.cs @@ -147,24 +147,44 @@ public class DungeonGenerator { 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].type = Room.TileType.GROUND; - else - path.tiles.Add(pos1, new GenTile(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, new GenTile(Room.TileType.WALL)); - } - } + if (path.tiles.ContainsKey(pos1)) + path.tiles[pos1].type = Room.TileType.GROUND; + else + path.tiles.Add(pos1, new GenTile(Room.TileType.GROUND)); + + Vector2Int pos2 = new Vector2Int(x1 + 1, y1); + if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2)) + path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.RIGHT)); + pos2 = new Vector2Int(x1 - 1, y1); + if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2)) + path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.LEFT)); + pos2 = new Vector2Int(x1, y1 + 1); + if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2)) + path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.TOP)); + pos2 = new Vector2Int(x1, y1 - 1); + if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2)) + path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.BOTTOM)); + } + 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 pos2 = new Vector2Int(x1 + 1, y1 + 1); + if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2)) + path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.TOP_RIGHT)); + pos2 = new Vector2Int(x1 - 1, y1 + 1); + if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2)) + path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.TOP_LEFT)); + pos2 = new Vector2Int(x1 + 1, y1 - 1); + if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2)) + path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.BOTTOM_RIGHT)); + pos2 = new Vector2Int(x1 - 1, y1 - 1); + if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2)) + path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.BOTTOM_LEFT)); } if (r.AllDoors().Count > 0) throw new NotSupportedException("Paths should not have any doors"); diff --git a/Assets/Scripts/Generation/GenTile.cs b/Assets/Scripts/Generation/GenTile.cs index e66509e..ffe3dab 100644 --- a/Assets/Scripts/Generation/GenTile.cs +++ b/Assets/Scripts/Generation/GenTile.cs @@ -6,15 +6,15 @@ public class GenTile { public enum Position { - TOP_LEFT = 0, - TOP = 1, - TOP_RIGHT = 2, + BOTTOM_LEFT = 0, + BOTTOM = 1, + BOTTOM_RIGHT = 2, LEFT = 3, CENTER = 4, RIGHT = 5, - BOTTOM_LEFT = 6, - BOTTOM = 7, - BOTTOM_RIGHT = 8 + TOP_LEFT = 6, + TOP = 7, + TOP_RIGHT = 8 } public Room.TileType type; diff --git a/Assets/Scripts/Generation/GenerationProcessor.cs b/Assets/Scripts/Generation/GenerationProcessor.cs index b39ec94..300c003 100644 --- a/Assets/Scripts/Generation/GenerationProcessor.cs +++ b/Assets/Scripts/Generation/GenerationProcessor.cs @@ -27,13 +27,13 @@ public class GenerationProcessor { switch (tiles[v].position) { case GenTile.Position.BOTTOM: - rotation = 0; + rotation = 180; break; case GenTile.Position.LEFT: rotation = 90; break; case GenTile.Position.TOP: - rotation = 180; + rotation = 0; break; case GenTile.Position.RIGHT: rotation = 270; @@ -44,16 +44,16 @@ public class GenerationProcessor { switch (tiles[v].position) { case GenTile.Position.BOTTOM_LEFT: - rotation = 0; - break; - case GenTile.Position.TOP_LEFT: rotation = 90; + break; + case GenTile.Position.TOP_LEFT: + rotation = 0; break; case GenTile.Position.TOP_RIGHT: - rotation = 180; + rotation = 270; break; case GenTile.Position.BOTTOM_RIGHT: - rotation = 270; + rotation = 180; break; } break;