From 1199d14774220d271bf840a221060c93485615ae Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Mon, 23 Apr 2018 01:16:25 +0200 Subject: [PATCH] Stones A rock solid commit! --- Assets/Scripts/Generation/DungeonGenerator.cs | 85 ++++++++++--------- Assets/Scripts/Generation/GenRoom.cs | 4 - .../Scripts/Generation/GenerationProcessor.cs | 2 + 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/Assets/Scripts/Generation/DungeonGenerator.cs b/Assets/Scripts/Generation/DungeonGenerator.cs index 0d11e41..17eac4d 100644 --- a/Assets/Scripts/Generation/DungeonGenerator.cs +++ b/Assets/Scripts/Generation/DungeonGenerator.cs @@ -17,9 +17,6 @@ public class DungeonGenerator { // All rooms except the three above public HashSet rooms; - private const float percentageRocks = 0.03f; - private const int maxRockCluster = 5; - public void Generate() { int minRoomSize = 50; rooms = new HashSet(); @@ -190,18 +187,29 @@ public class DungeonGenerator { throw new NotSupportedException("Paths should not have any doors"); } - //foreach (GenRoom r in rooms) { - // generateInterior (r); - //} - start = root.r; - end = null; foreach ( GenRoom r in rooms ) { + end = null; + foreach ( GenRoom r in rooms ) { if ( end == null || r.bounds.x > end.bounds.x ) - end = r; + end = r; } rooms.Remove(start); - rooms.Remove(end); + rooms.Remove(end); + + foreach (GenRoom r in rooms) + { + GenerateInterior(r); + } + + foreach (Vector2Int v in allDoors) { + foreach (GenRoom r in rooms) { + for (int x = -TUNNEL_THICKNESS; x < TUNNEL_THICKNESS; x++) + for (int y = -TUNNEL_THICKNESS; y < TUNNEL_THICKNESS; y++) + if (r.tiles.ContainsKey(v + new Vector2Int(x, y)) && r.tiles[v + new Vector2Int(x, y)].type == Room.TileType.ROCK) + r.tiles[v + new Vector2Int(x, y)].type = Room.TileType.GROUND; + } + } foreach ( GenRoom r in rooms ) makeRoomRelative(r); @@ -393,37 +401,34 @@ public class DungeonGenerator { } } - public static void generateInterior(GenRoom r) { - //int width = r.bounds.width; - //int height = r.bounds.height; - - //Vector2Int root = new Vector2Int (1, 1); - //Random rand = new Random (System.DateTime.Now); - - //for(int x = 0; i != width; ++x) - //{ - // for(int y = 0; y != width; ++y) - // { - // Room.TileType tempTile; - // r.tiles.TryGetValue (root + new Vector2Int (x, y), tempTile); - - // if(rand.NextDouble() <= percentageRocks && tempTile.Equals(Room.TileType.GROUND) - // { - // int clusterSize = rand.Next (1, maxRockCluster + 1); - // r.tiles.Add (root + new Vector2Int (x, y), Room.TileType.ROCK); - - // for(int i = 0; i != clusterSize; ++i) - // { - // Vector2Int newRock = root + new Vector2Int(x + rand.Next(0, 2), y + rand.Next(0, 2)); - // r.tiles.TryGetValue (newRock, tempTile); - // if(!tempTile.Equals(Room.TileType.GROUND)) - // break; - - - - - + public void GenerateInterior(GenRoom r) { + Vector2Int root = new Vector2Int (1, 1); + for (int x = r.bounds.x; x < r.bounds.x + r.bounds.width; x++) + { + for (int y = r.bounds.y; y < r.bounds.y + r.bounds.height; y++) + { + Vector2Int pos = new Vector2Int(x, y); + if (!r.tiles.ContainsKey(pos) || r.tiles[pos].type != Room.TileType.GROUND) + continue; + float prob = 0.0075f; + if (UnityEngine.Random.value > 1 - prob) + { + r.tiles[pos].type = Room.TileType.ROCK; + } + if (UnityEngine.Random.value > 1 - prob * 2) + { + int count = (int ) (UnityEngine.Random.value * UnityEngine.Random.value * 6); + for (int i = 0; i < count; i++) { + Vector2Int pos2 = pos + new Vector2Int( + (int)((UnityEngine.Random.value - 0.5) * 3), + (int)((UnityEngine.Random.value - 0.5) * 3)); + if (r.tiles.ContainsKey(pos2) && r.tiles[pos2].type == Room.TileType.GROUND) + r.tiles[pos2].type = Room.TileType.ROCK; + } + } + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/Generation/GenRoom.cs b/Assets/Scripts/Generation/GenRoom.cs index cd5fe54..810bac4 100644 --- a/Assets/Scripts/Generation/GenRoom.cs +++ b/Assets/Scripts/Generation/GenRoom.cs @@ -42,8 +42,4 @@ public class GenRoom { ret.UnionWith(doorsRight); return ret; } - - public void generateInteror() { - - } } \ No newline at end of file diff --git a/Assets/Scripts/Generation/GenerationProcessor.cs b/Assets/Scripts/Generation/GenerationProcessor.cs index 300c003..1f50f79 100644 --- a/Assets/Scripts/Generation/GenerationProcessor.cs +++ b/Assets/Scripts/Generation/GenerationProcessor.cs @@ -78,6 +78,8 @@ public class GenerationProcessor { private GameObject CreateGOFromType(Vector2 v, int rotation, ExtendedTileType t, GameObject root) { GameObject tmp = null; + //if (t == ExtendedTileType.BorderInner || t == ExtendedTileType.BorderOuter || t == ExtendedTileType.BorderInner) + // CreateGOFromType(v, rotation, ExtendedTileType.Ground, root); if ( prefabs.ContainsKey(t) && root != null ) { tmp = Object.Instantiate(prefabs[t], root.transform); tmp.transform.position = v;