From ef8c54e9a053ccee26112b1e9a7554542b14f8e9 Mon Sep 17 00:00:00 2001 From: ALoTron <34157676+ALoTron@users.noreply.github.com> Date: Sun, 22 Apr 2018 18:23:05 +0200 Subject: [PATCH] Started with interiorGeneration() WIP feel free to continie --- Assets/Scripts/Generation/DungeonGenerator.cs | 43 +++++++++++++++++++ Assets/Scripts/Generation/GenRoom.cs | 4 ++ 2 files changed, 47 insertions(+) diff --git a/Assets/Scripts/Generation/DungeonGenerator.cs b/Assets/Scripts/Generation/DungeonGenerator.cs index 90093d5..8dd1d8c 100644 --- a/Assets/Scripts/Generation/DungeonGenerator.cs +++ b/Assets/Scripts/Generation/DungeonGenerator.cs @@ -17,6 +17,9 @@ public class DungeonGenerator { // All rooms except the three above public HashSet rooms; + private const float percentageRocks = 0.03; + private const int maxRockCluster = 5; + public void Generate() { int minRoomSize = 50; rooms = new HashSet(); @@ -149,6 +152,12 @@ public class DungeonGenerator { r.tiles[v] = Room.TileType.DOOR; } + foreach (GenRoom r in rooms) { + generateInterior (r); + } + + rooms.Add(path); + start = root.r; end = null; foreach ( GenRoom r in rooms ) { if ( end == null || r.bounds.x > end.bounds.x ) @@ -344,4 +353,38 @@ 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; + + + + + + + + } } \ No newline at end of file diff --git a/Assets/Scripts/Generation/GenRoom.cs b/Assets/Scripts/Generation/GenRoom.cs index ed24240..c4a4d7f 100644 --- a/Assets/Scripts/Generation/GenRoom.cs +++ b/Assets/Scripts/Generation/GenRoom.cs @@ -35,4 +35,8 @@ public class GenRoom { ret.UnionWith(doorsRight); return ret; } + + public void generateInteror() + { + b } \ No newline at end of file