From 2c67b3ed2380723fd61fa869de168a57751df028 Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Sun, 22 Apr 2018 21:07:09 +0200 Subject: [PATCH 1/4] Preparation for texture rotations --- .../Scripts/Generation/GenerationProcessor.cs | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Assets/Scripts/Generation/GenerationProcessor.cs b/Assets/Scripts/Generation/GenerationProcessor.cs index d376a1f..ee5854c 100644 --- a/Assets/Scripts/Generation/GenerationProcessor.cs +++ b/Assets/Scripts/Generation/GenerationProcessor.cs @@ -11,40 +11,41 @@ public class GenerationProcessor { this.prefabs = prefabs; } - public GameObject ProcessRoom(Dictionary d) { + public GameObject ProcessRoom(Dictionary tiles) { GameObject root = new GameObject { name = "Room" }; - foreach ( Vector2Int v in d.Keys ) { + foreach ( Vector2Int v in tiles.Keys ) { bool left = false; bool top = false; bool right = false; bool bottom = false; // left bound - if ( d.ContainsKey(v + new Vector2Int(-1, 0)) ) { - if ( d[v + new Vector2Int(-1, 0)] == d[v] ) { + if ( tiles.ContainsKey(v + new Vector2Int(-1, 0)) ) { + if ( tiles[v + new Vector2Int(-1, 0)] == tiles[v] ) { left = true; } } // top bound - if ( d.ContainsKey(v + new Vector2Int(0, 1)) ) { - if ( d[v + new Vector2Int(0, 1)] == d[v] ) { + if ( tiles.ContainsKey(v + new Vector2Int(0, 1)) ) { + if ( tiles[v + new Vector2Int(0, 1)] == tiles[v] ) { top = true; } } // right bound - if ( d.ContainsKey(v + new Vector2Int(1, 0)) ) { - if ( d[v + new Vector2Int(1, 0)] == d[v] ) { + if ( tiles.ContainsKey(v + new Vector2Int(1, 0)) ) { + if ( tiles[v + new Vector2Int(1, 0)] == tiles[v] ) { right = true; } } // bottom bound - if ( d.ContainsKey(v + new Vector2Int(0, -1)) ) { - if ( d[v + new Vector2Int(0, -1)] == d[v] ) { + if ( tiles.ContainsKey(v + new Vector2Int(0, -1)) ) { + if ( tiles[v + new Vector2Int(0, -1)] == tiles[v] ) { bottom = true; } } ExtendedTileType type = ExtendedTileType.Ground; + int rotation = 0; // --------------------------------------------------------------------------------------------------------------------------------------------- // ^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~ // @@ -55,10 +56,13 @@ public class GenerationProcessor { // // ^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~ // --------------------------------------------------------------------------------------------------------------------------------------------- - switch ( d[v] ) { + switch ( tiles[v] ) { case Room.TileType.WALL: type = ExtendedTileType.BorderSingle; - if ( top && left && d.ContainsKey(v + new Vector2Int(-1, -1)) || top && right && d.ContainsKey(v + new Vector2Int(1, -1)) || right && bottom && d.ContainsKey(v + new Vector2Int(1, 1)) || left && bottom && d.ContainsKey(v + new Vector2Int(-1, 1)) ) { + if ( top && left && tiles.ContainsKey(v + new Vector2Int(-1, -1)) + || top && right && tiles.ContainsKey(v + new Vector2Int(1, -1)) + || right && bottom && tiles.ContainsKey(v + new Vector2Int(1, 1)) + || left && bottom && tiles.ContainsKey(v + new Vector2Int(-1, 1)) ) { type = ExtendedTileType.BorderOuter; } else if ( top && left || top && right || right && bottom || left && bottom ) { type = ExtendedTileType.BorderInner; @@ -121,17 +125,18 @@ public class GenerationProcessor { break; } - CreateGOFromType(v, type, root); + CreateGOFromType(v, rotation, type, root); } return root; } - private GameObject CreateGOFromType(Vector2 v, ExtendedTileType t, GameObject root) { + private GameObject CreateGOFromType(Vector2 v, int rotation, ExtendedTileType t, GameObject root) { GameObject tmp = null; if ( prefabs.ContainsKey(t) && root != null ) { - tmp = GameObject.Instantiate(prefabs[t], root.transform); + tmp = Object.Instantiate(prefabs[t], root.transform); tmp.transform.position = v; + tmp.transform.Rotate(new Vector3(0, 0, rotation)); } return tmp; } From b13a13cfdee00f47db005126f563ae920c212295 Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Sun, 22 Apr 2018 21:22:20 +0200 Subject: [PATCH 2/4] Added GenTile --- Assets/Scripts/Generation/DungeonGenerator.cs | 12 +++++----- Assets/Scripts/Generation/GenRoom.cs | 2 +- Assets/Scripts/Generation/GenTile.cs | 22 +++++++++++++++++++ Assets/Scripts/Generation/GenTile.cs.meta | 11 ++++++++++ .../Scripts/Generation/GenerationProcessor.cs | 8 ++++--- 5 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 Assets/Scripts/Generation/GenTile.cs create mode 100644 Assets/Scripts/Generation/GenTile.cs.meta diff --git a/Assets/Scripts/Generation/DungeonGenerator.cs b/Assets/Scripts/Generation/DungeonGenerator.cs index 88d7f99..28a67fa 100644 --- a/Assets/Scripts/Generation/DungeonGenerator.cs +++ b/Assets/Scripts/Generation/DungeonGenerator.cs @@ -127,11 +127,11 @@ 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), Room.TileType.WALL); + r.tiles.Add(new Vector2Int(x1, y1), new GenTile(Room.TileType.WALL)); } 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++ ) { - r.tiles[new Vector2Int(x1, y1)] = Room.TileType.GROUND; + r.tiles[new Vector2Int(x1, y1)].type = Room.TileType.GROUND; } allDoors.UnionWith(r.AllDoors()); foreach ( Vector2Int v in r.AllDoors() ) { @@ -139,7 +139,7 @@ public class DungeonGenerator { if ( !r.bounds.Contains(v) ) throw new NotSupportedException("This is a bug where doors land in the wrong room. It should have been fixed."); else - r.tiles[v] = Room.TileType.DOOR; + r.tiles[v].type = Room.TileType.DOOR; } } @@ -151,15 +151,15 @@ public class DungeonGenerator { { Vector2Int pos1 = new Vector2Int(x1, y1); if (path.tiles.ContainsKey(pos1)) - path.tiles[pos1] = Room.TileType.GROUND; + path.tiles[pos1].type = Room.TileType.GROUND; else - path.tiles.Add(pos1, Room.TileType.GROUND); + 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, Room.TileType.WALL); + path.tiles.Add(pos2, new GenTile(Room.TileType.WALL)); } } if (r.AllDoors().Count > 0) diff --git a/Assets/Scripts/Generation/GenRoom.cs b/Assets/Scripts/Generation/GenRoom.cs index 2b9fa56..def7eba 100644 --- a/Assets/Scripts/Generation/GenRoom.cs +++ b/Assets/Scripts/Generation/GenRoom.cs @@ -17,7 +17,7 @@ public class GenRoom { // The position of the anchor of the room in world space. This should be the top left corner of the room, but may be any point in the world. public Vector2Int roomPosition; // All positions are in room space relative to the room's anchor - public Dictionary tiles = new Dictionary(); + public Dictionary tiles = new Dictionary(); public float Distance(GenRoom r) { return Math.Abs(GetCenter().x - r.GetCenter().x) + Math.Abs(GetCenter().y - r.GetCenter().y); diff --git a/Assets/Scripts/Generation/GenTile.cs b/Assets/Scripts/Generation/GenTile.cs new file mode 100644 index 0000000..e8a2ae9 --- /dev/null +++ b/Assets/Scripts/Generation/GenTile.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class GenTile +{ + public enum Position + { + TOP, BOTTOM, LEFT, RIGHT, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT + } + public Room.TileType type; + public Position position; + + public GenTile() + { + + } + + public GenTile(Room.TileType type) { + this.type = type; + } +} diff --git a/Assets/Scripts/Generation/GenTile.cs.meta b/Assets/Scripts/Generation/GenTile.cs.meta new file mode 100644 index 0000000..63c77e7 --- /dev/null +++ b/Assets/Scripts/Generation/GenTile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1b8dce5bdb3204011a32ee1b512a4296 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Generation/GenerationProcessor.cs b/Assets/Scripts/Generation/GenerationProcessor.cs index ee5854c..d2133d3 100644 --- a/Assets/Scripts/Generation/GenerationProcessor.cs +++ b/Assets/Scripts/Generation/GenerationProcessor.cs @@ -11,7 +11,7 @@ public class GenerationProcessor { this.prefabs = prefabs; } - public GameObject ProcessRoom(Dictionary tiles) { + public GameObject ProcessRoom(Dictionary tiles) { GameObject root = new GameObject { name = "Room" }; @@ -56,7 +56,7 @@ public class GenerationProcessor { // // ^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~ // --------------------------------------------------------------------------------------------------------------------------------------------- - switch ( tiles[v] ) { + switch ( tiles[v].type ) { case Room.TileType.WALL: type = ExtendedTileType.BorderSingle; if ( top && left && tiles.ContainsKey(v + new Vector2Int(-1, -1)) @@ -66,7 +66,9 @@ public class GenerationProcessor { type = ExtendedTileType.BorderOuter; } else if ( top && left || top && right || right && bottom || left && bottom ) { type = ExtendedTileType.BorderInner; - } + } else { + // BorderSingle + } break; case Room.TileType.GROUND: type = ExtendedTileType.Ground; 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 3/4] 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: From c26844f74b99f1364a68ac3c3d4818dd3d2f44f7 Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Sun, 22 Apr 2018 23:24:58 +0200 Subject: [PATCH 4/4] =?UTF-8?q?W=C3=A4nde=20der=20R=C3=A4ume=20werden=20ko?= =?UTF-8?q?rrekt=20angezeigt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gänge fehlen noch --- .../Scripts/Generation/GenerationProcessor.cs | 255 ++++++++++-------- 1 file changed, 148 insertions(+), 107 deletions(-) diff --git a/Assets/Scripts/Generation/GenerationProcessor.cs b/Assets/Scripts/Generation/GenerationProcessor.cs index 920eaed..b39ec94 100644 --- a/Assets/Scripts/Generation/GenerationProcessor.cs +++ b/Assets/Scripts/Generation/GenerationProcessor.cs @@ -16,74 +16,47 @@ public class GenerationProcessor { name = "Room" }; foreach ( Vector2Int v in tiles.Keys ) { - bool left = false; - bool top = false; - bool right = false; - bool bottom = false; - // left bound - if ( tiles.ContainsKey(v + new Vector2Int(-1, 0)) ) { - if ( tiles[v + new Vector2Int(-1, 0)] == tiles[v] ) { - left = true; - } - } - // top bound - if ( tiles.ContainsKey(v + new Vector2Int(0, 1)) ) { - if ( tiles[v + new Vector2Int(0, 1)] == tiles[v] ) { - top = true; - } - } - // right bound - if ( tiles.ContainsKey(v + new Vector2Int(1, 0)) ) { - if ( tiles[v + new Vector2Int(1, 0)] == tiles[v] ) { - right = true; - } - } - // bottom bound - if ( tiles.ContainsKey(v + new Vector2Int(0, -1)) ) { - if ( tiles[v + new Vector2Int(0, -1)] == tiles[v] ) { - bottom = true; - } - } - ExtendedTileType type = ExtendedTileType.Ground; + ExtendedTileType type = ExtendedTileType.Ground; int rotation = 0; - // --------------------------------------------------------------------------------------------------------------------------------------------- - // ^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~ - // - // *** W A R N I N G B A D C O D E A H E A D ! ! ! *** - // __________________________________________________________________________ - // - // DON'T WATCH, UNLESS YOU WANT TO GET TRAUMATIZED! - // - // ^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~ - // --------------------------------------------------------------------------------------------------------------------------------------------- - switch ( tiles[v].type ) { + switch ( tiles[v].type ) { case Room.TileType.WALL: - type = ExtendedTileType.BorderSingle; - if ( top && left && tiles.ContainsKey(v + new Vector2Int(-1, -1)) - || top && right && tiles.ContainsKey(v + new Vector2Int(1, -1)) - || right && bottom && tiles.ContainsKey(v + new Vector2Int(1, 1)) - || left && bottom && tiles.ContainsKey(v + new Vector2Int(-1, 1)) ) { - type = ExtendedTileType.BorderOuter; - } else if ( top && left || top && right || right && bottom || left && bottom ) { - type = ExtendedTileType.BorderInner; - } else { - // BorderSingle - if (tiles[v].position != null) { - switch (tiles[v].position) { - case GenTile.Position.BOTTOM: + type = getCorrectWallType(tiles, v); + switch (type) + { + case ExtendedTileType.BorderSingle: + switch (tiles[v].position) + { + case GenTile.Position.BOTTOM: rotation = 0; break; case GenTile.Position.LEFT: rotation = 90; break; - case GenTile.Position.TOP: - rotation = 180; + case GenTile.Position.TOP: + rotation = 180; + break; + case GenTile.Position.RIGHT: + rotation = 270; break; - case GenTile.Position.RIGHT: - rotation = 270; - break; } - } + break; + case ExtendedTileType.BorderInner: + switch (tiles[v].position) + { + case GenTile.Position.BOTTOM_LEFT: + rotation = 0; + break; + case GenTile.Position.TOP_LEFT: + rotation = 90; + break; + case GenTile.Position.TOP_RIGHT: + rotation = 180; + break; + case GenTile.Position.BOTTOM_RIGHT: + rotation = 270; + break; + } + break; } break; case Room.TileType.GROUND: @@ -93,53 +66,7 @@ public class GenerationProcessor { type = ExtendedTileType.Door; break; case Room.TileType.ROCK: - type = ExtendedTileType.Rock; - if ( top && !right && !left && !bottom ) { - type = ExtendedTileType.RockU; - } - if ( left && !right && !bottom && !top ) { - type = ExtendedTileType.RockL; - } - if ( right && !bottom && !left && !top ) { - type = ExtendedTileType.RockR; - } - if ( bottom && !right && !left && !top ) { - type = ExtendedTileType.RockD; - } - if ( left && top && !bottom && !right ) { - type = ExtendedTileType.RockLU; - } - if ( left && right && !top && !bottom ) { - type = ExtendedTileType.RockLR; - } - if ( left && bottom && !right && !top ) { - type = ExtendedTileType.RockLD; - } - if ( top && right && !left && !bottom ) { - type = ExtendedTileType.RockUR; - } - if ( top && bottom && !left && !right ) { - type = ExtendedTileType.RockUD; - } - if ( right && bottom && !top && !left ) { - type = ExtendedTileType.RockRD; - } - - if ( left && top && bottom && !right ) { - type = ExtendedTileType.RockLUD; - } - if ( left && top && right && !bottom ) { - type = ExtendedTileType.RockLUR; - } - if ( top && right && bottom && !left ) { - type = ExtendedTileType.RockURD; - } - if ( left && right && bottom && !top ) { - type = ExtendedTileType.RockLRD; - } - if ( left && top && right && bottom ) { - type = ExtendedTileType.RockLURD; - } + type = getCorrectRockType(tiles, v); break; } @@ -158,4 +85,118 @@ public class GenerationProcessor { } return tmp; } -} + + private int CountSpecificNeighbours(Dictionary tiles, Vector2Int position, Room.TileType type) { + int counter = 0; + Vector2Int toCheck = position + new Vector2Int(0, -1); + if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == type) + counter++; + toCheck = position + new Vector2Int(-1, 0); + if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == type) + counter++; + toCheck = position + new Vector2Int(0, 1); + if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == type) + counter++; + toCheck = position + new Vector2Int(1, 0); + if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == type) + counter++; + return counter; + } + + private ExtendedTileType getCorrectWallType(Dictionary tiles, Vector2Int position){ + int groundNumber = CountSpecificNeighbours(tiles, position, Room.TileType.GROUND); + switch(groundNumber){ + case 0: + return ExtendedTileType.BorderInner; + case 2: + return ExtendedTileType.BorderOuter; + default: + return ExtendedTileType.BorderSingle; + } + } + + private ExtendedTileType getCorrectRockType(Dictionary tiles, Vector2Int position){ + + ExtendedTileType type = ExtendedTileType.Rock; + + bool left = false; + bool top = false; + bool right = false; + bool bottom = false; + + Vector2Int toCheck = position + new Vector2Int(0, -1); + if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.ROCK) + bottom = true; + toCheck = position + new Vector2Int(-1, 0); + if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.ROCK) + left = true; + toCheck = position + new Vector2Int(0, 1); + if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.ROCK) + top = true; + toCheck = position + new Vector2Int(1, 0); + if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.ROCK) + right = true; + + if (top && !right && !left && !bottom) + { + return ExtendedTileType.RockU; + } + if (left && !right && !bottom && !top) + { + return ExtendedTileType.RockL; + } + if (right && !bottom && !left && !top) + { + return ExtendedTileType.RockR; + } + if (bottom && !right && !left && !top) + { + return ExtendedTileType.RockD; + } + if (left && top && !bottom && !right) + { + return ExtendedTileType.RockLU; + } + if (left && right && !top && !bottom) + { + return ExtendedTileType.RockLR; + } + if (left && bottom && !right && !top) + { + return ExtendedTileType.RockLD; + } + if (top && right && !left && !bottom) + { + return ExtendedTileType.RockUR; + } + if (top && bottom && !left && !right) + { + return ExtendedTileType.RockUD; + } + if (right && bottom && !top && !left) + { + return ExtendedTileType.RockRD; + } + if (left && top && bottom && !right) + { + return ExtendedTileType.RockLUD; + } + if (left && top && right && !bottom) + { + return ExtendedTileType.RockLUR; + } + if (top && right && bottom && !left) + { + return ExtendedTileType.RockURD; + } + if (left && right && bottom && !top) + { + return ExtendedTileType.RockLRD; + } + if (left && top && right && bottom) + { + return ExtendedTileType.RockLURD; + } + return type; + } +} \ No newline at end of file