Merge remote-tracking branch 'origin/PiegamesDev'
This commit is contained in:
commit
0ed78a8bce
4 changed files with 99 additions and 76 deletions
|
@ -17,9 +17,6 @@ public class DungeonGenerator {
|
||||||
// All rooms except the three above
|
// All rooms except the three above
|
||||||
public HashSet<GenRoom> rooms;
|
public HashSet<GenRoom> rooms;
|
||||||
|
|
||||||
private const float percentageRocks = 0.03f;
|
|
||||||
private const int maxRockCluster = 5;
|
|
||||||
|
|
||||||
public void Generate() {
|
public void Generate() {
|
||||||
int minRoomSize = 50;
|
int minRoomSize = 50;
|
||||||
rooms = new HashSet<GenRoom>();
|
rooms = new HashSet<GenRoom>();
|
||||||
|
@ -147,41 +144,72 @@ public class DungeonGenerator {
|
||||||
|
|
||||||
path = new GenRoom();
|
path = new GenRoom();
|
||||||
foreach (GenRoom r in rooms2)
|
foreach (GenRoom r in rooms2)
|
||||||
{
|
{
|
||||||
for (int x1 = r.bounds.x; x1 < r.bounds.x + r.bounds.width; x1++)
|
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++)
|
for (int y1 = r.bounds.y; y1 < r.bounds.y + r.bounds.height; y1++)
|
||||||
{
|
{
|
||||||
Vector2Int pos1 = new Vector2Int(x1, y1);
|
Vector2Int pos1 = new Vector2Int(x1, y1);
|
||||||
if (path.tiles.ContainsKey(pos1))
|
if (path.tiles.ContainsKey(pos1))
|
||||||
path.tiles[pos1].type = Room.TileType.GROUND;
|
path.tiles[pos1].type = Room.TileType.GROUND;
|
||||||
else
|
else
|
||||||
path.tiles.Add(pos1, new GenTile(Room.TileType.GROUND));
|
path.tiles.Add(pos1, new GenTile(Room.TileType.GROUND));
|
||||||
for (int x2 = x1 - 1; x2 <= x1 + 1; x2++)
|
|
||||||
{
|
Vector2Int pos2 = new Vector2Int(x1 + 1, y1);
|
||||||
for (int y2 = y1 - 1; y2 <= y1 + 1; y2++)
|
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
|
||||||
{
|
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.RIGHT));
|
||||||
Vector2Int pos2 = new Vector2Int(x2, y2);
|
pos2 = new Vector2Int(x1 - 1, y1);
|
||||||
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
|
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
|
||||||
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL));
|
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.LEFT));
|
||||||
}
|
pos2 = new Vector2Int(x1, y1 + 1);
|
||||||
}
|
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
|
||||||
|
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.TOP));
|
||||||
|
pos2 = new Vector2Int(x1, y1 - 1);
|
||||||
|
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
|
||||||
|
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.BOTTOM));
|
||||||
|
}
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
Vector2Int pos2 = new Vector2Int(x1 + 1, y1 + 1);
|
||||||
|
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
|
||||||
|
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.TOP_RIGHT));
|
||||||
|
pos2 = new Vector2Int(x1 - 1, y1 + 1);
|
||||||
|
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
|
||||||
|
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.TOP_LEFT));
|
||||||
|
pos2 = new Vector2Int(x1 + 1, y1 - 1);
|
||||||
|
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
|
||||||
|
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.BOTTOM_RIGHT));
|
||||||
|
pos2 = new Vector2Int(x1 - 1, y1 - 1);
|
||||||
|
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
|
||||||
|
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.BOTTOM_LEFT));
|
||||||
}
|
}
|
||||||
if (r.AllDoors().Count > 0)
|
if (r.AllDoors().Count > 0)
|
||||||
throw new NotSupportedException("Paths should not have any doors");
|
throw new NotSupportedException("Paths should not have any doors");
|
||||||
}
|
}
|
||||||
|
|
||||||
//foreach (GenRoom r in rooms) {
|
|
||||||
// generateInterior (r);
|
|
||||||
//}
|
|
||||||
|
|
||||||
start = root.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 )
|
if ( end == null || r.bounds.x > end.bounds.x )
|
||||||
end = r;
|
end = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
rooms.Remove(start);
|
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 )
|
foreach ( GenRoom r in rooms )
|
||||||
makeRoomRelative(r);
|
makeRoomRelative(r);
|
||||||
|
@ -373,37 +401,34 @@ public class DungeonGenerator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateInterior(GenRoom r) {
|
public 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;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -42,8 +42,4 @@ public class GenRoom {
|
||||||
ret.UnionWith(doorsRight);
|
ret.UnionWith(doorsRight);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateInteror() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -6,15 +6,15 @@ public class GenTile
|
||||||
{
|
{
|
||||||
public enum Position
|
public enum Position
|
||||||
{
|
{
|
||||||
TOP_LEFT = 0,
|
BOTTOM_LEFT = 0,
|
||||||
TOP = 1,
|
BOTTOM = 1,
|
||||||
TOP_RIGHT = 2,
|
BOTTOM_RIGHT = 2,
|
||||||
LEFT = 3,
|
LEFT = 3,
|
||||||
CENTER = 4,
|
CENTER = 4,
|
||||||
RIGHT = 5,
|
RIGHT = 5,
|
||||||
BOTTOM_LEFT = 6,
|
TOP_LEFT = 6,
|
||||||
BOTTOM = 7,
|
TOP = 7,
|
||||||
BOTTOM_RIGHT = 8
|
TOP_RIGHT = 8
|
||||||
}
|
}
|
||||||
|
|
||||||
public Room.TileType type;
|
public Room.TileType type;
|
||||||
|
|
|
@ -27,13 +27,13 @@ public class GenerationProcessor {
|
||||||
switch (tiles[v].position)
|
switch (tiles[v].position)
|
||||||
{
|
{
|
||||||
case GenTile.Position.BOTTOM:
|
case GenTile.Position.BOTTOM:
|
||||||
rotation = 0;
|
rotation = 180;
|
||||||
break;
|
break;
|
||||||
case GenTile.Position.LEFT:
|
case GenTile.Position.LEFT:
|
||||||
rotation = 90;
|
rotation = 90;
|
||||||
break;
|
break;
|
||||||
case GenTile.Position.TOP:
|
case GenTile.Position.TOP:
|
||||||
rotation = 180;
|
rotation = 0;
|
||||||
break;
|
break;
|
||||||
case GenTile.Position.RIGHT:
|
case GenTile.Position.RIGHT:
|
||||||
rotation = 270;
|
rotation = 270;
|
||||||
|
@ -44,16 +44,16 @@ public class GenerationProcessor {
|
||||||
switch (tiles[v].position)
|
switch (tiles[v].position)
|
||||||
{
|
{
|
||||||
case GenTile.Position.BOTTOM_LEFT:
|
case GenTile.Position.BOTTOM_LEFT:
|
||||||
rotation = 0;
|
|
||||||
break;
|
|
||||||
case GenTile.Position.TOP_LEFT:
|
|
||||||
rotation = 90;
|
rotation = 90;
|
||||||
|
break;
|
||||||
|
case GenTile.Position.TOP_LEFT:
|
||||||
|
rotation = 0;
|
||||||
break;
|
break;
|
||||||
case GenTile.Position.TOP_RIGHT:
|
case GenTile.Position.TOP_RIGHT:
|
||||||
rotation = 180;
|
rotation = 270;
|
||||||
break;
|
break;
|
||||||
case GenTile.Position.BOTTOM_RIGHT:
|
case GenTile.Position.BOTTOM_RIGHT:
|
||||||
rotation = 270;
|
rotation = 180;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -78,6 +78,8 @@ public class GenerationProcessor {
|
||||||
|
|
||||||
private GameObject CreateGOFromType(Vector2 v, int rotation, ExtendedTileType t, GameObject root) {
|
private GameObject CreateGOFromType(Vector2 v, int rotation, ExtendedTileType t, GameObject root) {
|
||||||
GameObject tmp = null;
|
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 ) {
|
if ( prefabs.ContainsKey(t) && root != null ) {
|
||||||
tmp = Object.Instantiate(prefabs[t], root.transform);
|
tmp = Object.Instantiate(prefabs[t], root.transform);
|
||||||
tmp.transform.position = v;
|
tmp.transform.position = v;
|
||||||
|
@ -104,7 +106,7 @@ public class GenerationProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExtendedTileType getCorrectWallType(Dictionary<Vector2Int, GenTile> tiles, Vector2Int position){
|
private ExtendedTileType getCorrectWallType(Dictionary<Vector2Int, GenTile> tiles, Vector2Int position){
|
||||||
int groundNumber = CountSpecificNeighbours(tiles, position, Room.TileType.GROUND);
|
int groundNumber = CountSpecificNeighbours(tiles, position, Room.TileType.GROUND) + CountSpecificNeighbours(tiles, position, Room.TileType.ROCK);
|
||||||
switch(groundNumber){
|
switch(groundNumber){
|
||||||
case 0:
|
case 0:
|
||||||
return ExtendedTileType.BorderInner;
|
return ExtendedTileType.BorderInner;
|
||||||
|
|
Loading…
Add table
Reference in a new issue