1
0
Fork 0
A rock solid commit!
This commit is contained in:
Piegames 2018-04-23 01:16:25 +02:00
parent 336b57ae4e
commit 1199d14774
3 changed files with 47 additions and 44 deletions

View file

@ -17,9 +17,6 @@ public class DungeonGenerator {
// All rooms except the three above
public HashSet<GenRoom> rooms;
private const float percentageRocks = 0.03f;
private const int maxRockCluster = 5;
public void Generate() {
int minRoomSize = 50;
rooms = new HashSet<GenRoom>();
@ -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;
}
}
}
}
}
}

View file

@ -42,8 +42,4 @@ public class GenRoom {
ret.UnionWith(doorsRight);
return ret;
}
public void generateInteror() {
}
}

View file

@ -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;