1
0
Fork 0

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Triceraptodactyl 2018-04-24 22:15:30 +02:00
commit 5ef971a75b
2 changed files with 85 additions and 53 deletions

View file

@ -215,13 +215,26 @@ public class DungeonGenerator {
start.spawnpoints.Add(start.GetCenter());
end.spawnpoints.Add(end.GetCenter());
foreach (Vector2Int v in allDoors) {
foreach (GenRoom r in rooms) {
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;
}
{
GenRoom r = path;
if (r.tiles.ContainsKey(v + new Vector2Int(0, 1)) && r.tiles[v + new Vector2Int(0, 1)].type == Room.TileType.WALL)
r.tiles.Remove(v + new Vector2Int(0, 1));
if (r.tiles.ContainsKey(v + new Vector2Int(0, -1)) && r.tiles[v + new Vector2Int(0, -1)].type == Room.TileType.WALL)
r.tiles.Remove(v + new Vector2Int(0, -1));
if (r.tiles.ContainsKey(v + new Vector2Int(1, 0)) && r.tiles[v + new Vector2Int(1, 0)].type == Room.TileType.WALL)
r.tiles.Remove(v + new Vector2Int(1, 0));
if (r.tiles.ContainsKey(v + new Vector2Int(-1, 0)) && r.tiles[v + new Vector2Int(-1, 0)].type == Room.TileType.WALL)
r.tiles.Remove(v + new Vector2Int(-1, 0));
}
}
foreach ( GenRoom r in rooms )

View file

@ -21,7 +21,7 @@ public class GenerationProcessor {
switch ( tiles[v].type ) {
case Room.TileType.WALL:
type = GetCorrectWallType(tiles, v);
rotation = GetCorrectWallRotation(type, tiles[v].position);
rotation = GetCorrectWallRotation(tiles, v, type);
break;
case Room.TileType.GROUND:
type = GetRandomGroundType();
@ -55,25 +55,21 @@ public class GenerationProcessor {
return tmp;
}
private int CountSpecificNeighbours(Dictionary<Vector2Int, GenTile> 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<Vector2Int, GenTile> tiles, Vector2Int position) {
int groundNumber = CountSpecificNeighbours(tiles, position, Room.TileType.GROUND) + CountSpecificNeighbours(tiles, position, Room.TileType.ROCK);
int groundNumber = 0;
Vector2Int toCheck = position + new Vector2Int(0, -1);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL )
groundNumber++;
toCheck = position + new Vector2Int(-1, 0);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL )
groundNumber++;
toCheck = position + new Vector2Int(0, 1);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL )
groundNumber++;
toCheck = position + new Vector2Int(1, 0);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL )
groundNumber++;
switch ( groundNumber ) {
case 0:
return ExtendedTileType.BorderInner;
@ -84,43 +80,53 @@ public class GenerationProcessor {
}
}
private int GetCorrectWallRotation(ExtendedTileType type, GenTile.Position position) {
int rotation = 0;
private int GetCorrectWallRotation(Dictionary<Vector2Int, GenTile> tiles, Vector2Int v, ExtendedTileType type) {
switch ( type ) {
case ExtendedTileType.BorderSingle:
switch ( position ) {
case GenTile.Position.BOTTOM:
rotation = 180;
break;
case GenTile.Position.LEFT:
rotation = 90;
break;
case GenTile.Position.TOP:
rotation = 0;
break;
case GenTile.Position.RIGHT:
rotation = 270;
break;
}
Vector2Int toCheck = v + new Vector2Int(0, -1);
if(tiles.ContainsKey(toCheck) && (tiles[toCheck].type == Room.TileType.GROUND || tiles[toCheck].type == Room.TileType.GROUND))
return 0;
toCheck = v + new Vector2Int(-1, 0);
if(tiles.ContainsKey(toCheck) && (tiles[toCheck].type == Room.TileType.GROUND || tiles[toCheck].type == Room.TileType.GROUND))
return 270;
toCheck = v + new Vector2Int(0, 1);
if(tiles.ContainsKey(toCheck) && (tiles[toCheck].type == Room.TileType.GROUND || tiles[toCheck].type == Room.TileType.GROUND))
return 180;
toCheck = v + new Vector2Int(1, 0);
if(tiles.ContainsKey(toCheck) && (tiles[toCheck].type == Room.TileType.GROUND || tiles[toCheck].type == Room.TileType.GROUND))
return 90;
break;
case ExtendedTileType.BorderInner:
switch ( position ) {
case GenTile.Position.BOTTOM_LEFT:
rotation = 90;
toCheck = v + new Vector2Int(1, -1);
if(tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
return 0;
toCheck = v + new Vector2Int(1, 1);
if(tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
return 90;
toCheck = v + new Vector2Int(-1, 1);
if(tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
return 180;
toCheck = v + new Vector2Int(-1, -1);
if(tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
return 270;
break;
case GenTile.Position.TOP_LEFT:
rotation = 0;
break;
case GenTile.Position.TOP_RIGHT:
rotation = 270;
break;
case GenTile.Position.BOTTOM_RIGHT:
rotation = 180;
case ExtendedTileType.BorderOuter:
Vector2Int toCheck1 = v + new Vector2Int(0, -1);
Vector2Int toCheck2 = v + new Vector2Int(-1, 0);
if(tiles.ContainsKey(toCheck1) && tiles.ContainsKey(toCheck2) && tiles[toCheck1].type != Room.TileType.WALL && tiles[toCheck2].type != Room.TileType.WALL)
return 270;
toCheck1 = v + new Vector2Int(0, 1);
if(tiles.ContainsKey(toCheck1) && tiles.ContainsKey(toCheck2) && tiles[toCheck1].type != Room.TileType.WALL && tiles[toCheck2].type != Room.TileType.WALL)
return 180;
toCheck2 = v + new Vector2Int(1, 0);
if(tiles.ContainsKey(toCheck1) && tiles.ContainsKey(toCheck2) && tiles[toCheck1].type != Room.TileType.WALL && tiles[toCheck2].type != Room.TileType.WALL)
return 90;
toCheck1 = v + new Vector2Int(0, -1);
if(tiles.ContainsKey(toCheck1) && tiles.ContainsKey(toCheck2) && tiles[toCheck1].type != Room.TileType.WALL && tiles[toCheck2].type != Room.TileType.WALL)
return 0;
break;
}
break;
}
return rotation;
return 0;
}
private ExtendedTileType GetCorrectRockType(Dictionary<Vector2Int, GenTile> tiles, Vector2Int position) {
@ -175,7 +181,20 @@ public class GenerationProcessor {
}
private ExtendedTileType GetCorrectDoorType(Dictionary<Vector2Int, GenTile> tiles, Vector2Int position) {
int neighbourDoors = CountSpecificNeighbours(tiles, position, Room.TileType.DOOR);
int neighbourDoors = 0;
Vector2Int toCheck = position + new Vector2Int(0, -1);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR )
neighbourDoors++;
toCheck = position + new Vector2Int(-1, 0);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR )
neighbourDoors++;
toCheck = position + new Vector2Int(0, 1);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR )
neighbourDoors++;
toCheck = position + new Vector2Int(1, 0);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR )
neighbourDoors++;
switch ( neighbourDoors ) {
case 1:
return ExtendedTileType.DoorOuter;