From ede4f74a3aa773bb69f270a2214762079f2115b4 Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Sun, 22 Apr 2018 21:40:02 +0200 Subject: [PATCH] Rotation for straight wall --- Assets/Scripts/Generation/DungeonGenerator.cs | 26 +++++++++++-------- Assets/Scripts/Generation/GenRoom.cs | 2 +- Assets/Scripts/Generation/GenTile.cs | 26 ++++++++++++++++--- .../Scripts/Generation/GenerationProcessor.cs | 16 ++++++++++++ 4 files changed, 55 insertions(+), 15 deletions(-) diff --git a/Assets/Scripts/Generation/DungeonGenerator.cs b/Assets/Scripts/Generation/DungeonGenerator.cs index 28a67fa..85adea8 100644 --- a/Assets/Scripts/Generation/DungeonGenerator.cs +++ b/Assets/Scripts/Generation/DungeonGenerator.cs @@ -127,7 +127,9 @@ public class DungeonGenerator { 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++ ) { - r.tiles.Add(new Vector2Int(x1, y1), new GenTile(Room.TileType.WALL)); + int xMode = (x1 == r.bounds.x) ? -1 : (x1 == r.bounds.x + r.bounds.width - 1) ? 1 : 0; + int yMode = (y1 == r.bounds.y) ? -1 : (y1 == r.bounds.y + r.bounds.height - 1) ? 1 : 0; + r.tiles.Add(new Vector2Int(x1, y1), new GenTile(Room.TileType.WALL, GenTile.GetPosition(xMode,yMode))); } for ( int x1 = r.bounds.x + 1; x1 < r.bounds.x + r.bounds.width - 1; x1++ ) for ( int y1 = r.bounds.y + 1; y1 < r.bounds.y + r.bounds.height - 1; y1++ ) { @@ -150,17 +152,19 @@ public class DungeonGenerator { 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++) - { + 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(pos2) && !allDoors.Contains(pos2)) + path.tiles.Add(pos2, new GenTile(Room.TileType.WALL)); + } + } } if (r.AllDoors().Count > 0) throw new NotSupportedException("Paths should not have any doors"); diff --git a/Assets/Scripts/Generation/GenRoom.cs b/Assets/Scripts/Generation/GenRoom.cs index def7eba..cd5fe54 100644 --- a/Assets/Scripts/Generation/GenRoom.cs +++ b/Assets/Scripts/Generation/GenRoom.cs @@ -4,7 +4,7 @@ using UnityEngine; public class GenRoom { // ---Internal for generation only--- - // TODO make them package protcted please + // TODO make them package protected please public RectInt bounds = new RectInt(); public HashSet doorsUp = new HashSet(); diff --git a/Assets/Scripts/Generation/GenTile.cs b/Assets/Scripts/Generation/GenTile.cs index e8a2ae9..e66509e 100644 --- a/Assets/Scripts/Generation/GenTile.cs +++ b/Assets/Scripts/Generation/GenTile.cs @@ -6,17 +6,37 @@ public class GenTile { public enum Position { - TOP, BOTTOM, LEFT, RIGHT, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT + TOP_LEFT = 0, + TOP = 1, + TOP_RIGHT = 2, + LEFT = 3, + CENTER = 4, + RIGHT = 5, + BOTTOM_LEFT = 6, + BOTTOM = 7, + BOTTOM_RIGHT = 8 } + public Room.TileType type; public Position position; public GenTile() { + } + + public GenTile(Room.TileType type) + { + this.type = type; + } + + public GenTile(Room.TileType type, Position position) + { + this.type = type; + this.position = position; } - public GenTile(Room.TileType type) { - this.type = type; + public static Position GetPosition(int xMode, int yMode) { + return (Position) ((xMode + 1) + (yMode + 1) * 3); } } diff --git a/Assets/Scripts/Generation/GenerationProcessor.cs b/Assets/Scripts/Generation/GenerationProcessor.cs index d2133d3..920eaed 100644 --- a/Assets/Scripts/Generation/GenerationProcessor.cs +++ b/Assets/Scripts/Generation/GenerationProcessor.cs @@ -68,6 +68,22 @@ public class GenerationProcessor { type = ExtendedTileType.BorderInner; } else { // BorderSingle + if (tiles[v].position != null) { + switch (tiles[v].position) { + case GenTile.Position.BOTTOM: + rotation = 0; + break; + case GenTile.Position.LEFT: + rotation = 90; + break; + case GenTile.Position.TOP: + rotation = 180; + break; + case GenTile.Position.RIGHT: + rotation = 270; + break; + } + } } break; case Room.TileType.GROUND: