Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
5ef971a75b
2 changed files with 85 additions and 53 deletions
|
@ -215,13 +215,26 @@ public class DungeonGenerator {
|
||||||
start.spawnpoints.Add(start.GetCenter());
|
start.spawnpoints.Add(start.GetCenter());
|
||||||
end.spawnpoints.Add(end.GetCenter());
|
end.spawnpoints.Add(end.GetCenter());
|
||||||
|
|
||||||
foreach (Vector2Int v in allDoors) {
|
foreach (Vector2Int v in allDoors)
|
||||||
foreach (GenRoom r in rooms) {
|
{
|
||||||
|
foreach (GenRoom r in rooms)
|
||||||
|
{
|
||||||
for (int x = -TUNNEL_THICKNESS; x < TUNNEL_THICKNESS; x++)
|
for (int x = -TUNNEL_THICKNESS; x < TUNNEL_THICKNESS; x++)
|
||||||
for (int y = -TUNNEL_THICKNESS; y < TUNNEL_THICKNESS; y++)
|
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)
|
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;
|
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 )
|
foreach ( GenRoom r in rooms )
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class GenerationProcessor {
|
||||||
switch ( tiles[v].type ) {
|
switch ( tiles[v].type ) {
|
||||||
case Room.TileType.WALL:
|
case Room.TileType.WALL:
|
||||||
type = GetCorrectWallType(tiles, v);
|
type = GetCorrectWallType(tiles, v);
|
||||||
rotation = GetCorrectWallRotation(type, tiles[v].position);
|
rotation = GetCorrectWallRotation(tiles, v, type);
|
||||||
break;
|
break;
|
||||||
case Room.TileType.GROUND:
|
case Room.TileType.GROUND:
|
||||||
type = GetRandomGroundType();
|
type = GetRandomGroundType();
|
||||||
|
@ -55,25 +55,21 @@ public class GenerationProcessor {
|
||||||
return tmp;
|
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) {
|
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 ) {
|
switch ( groundNumber ) {
|
||||||
case 0:
|
case 0:
|
||||||
return ExtendedTileType.BorderInner;
|
return ExtendedTileType.BorderInner;
|
||||||
|
@ -84,43 +80,53 @@ public class GenerationProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetCorrectWallRotation(ExtendedTileType type, GenTile.Position position) {
|
private int GetCorrectWallRotation(Dictionary<Vector2Int, GenTile> tiles, Vector2Int v, ExtendedTileType type) {
|
||||||
int rotation = 0;
|
|
||||||
switch ( type ) {
|
switch ( type ) {
|
||||||
case ExtendedTileType.BorderSingle:
|
case ExtendedTileType.BorderSingle:
|
||||||
switch ( position ) {
|
Vector2Int toCheck = v + new Vector2Int(0, -1);
|
||||||
case GenTile.Position.BOTTOM:
|
if(tiles.ContainsKey(toCheck) && (tiles[toCheck].type == Room.TileType.GROUND || tiles[toCheck].type == Room.TileType.GROUND))
|
||||||
rotation = 180;
|
return 0;
|
||||||
break;
|
toCheck = v + new Vector2Int(-1, 0);
|
||||||
case GenTile.Position.LEFT:
|
if(tiles.ContainsKey(toCheck) && (tiles[toCheck].type == Room.TileType.GROUND || tiles[toCheck].type == Room.TileType.GROUND))
|
||||||
rotation = 90;
|
return 270;
|
||||||
break;
|
toCheck = v + new Vector2Int(0, 1);
|
||||||
case GenTile.Position.TOP:
|
if(tiles.ContainsKey(toCheck) && (tiles[toCheck].type == Room.TileType.GROUND || tiles[toCheck].type == Room.TileType.GROUND))
|
||||||
rotation = 0;
|
return 180;
|
||||||
break;
|
toCheck = v + new Vector2Int(1, 0);
|
||||||
case GenTile.Position.RIGHT:
|
if(tiles.ContainsKey(toCheck) && (tiles[toCheck].type == Room.TileType.GROUND || tiles[toCheck].type == Room.TileType.GROUND))
|
||||||
rotation = 270;
|
return 90;
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ExtendedTileType.BorderInner:
|
case ExtendedTileType.BorderInner:
|
||||||
switch ( position ) {
|
toCheck = v + new Vector2Int(1, -1);
|
||||||
case GenTile.Position.BOTTOM_LEFT:
|
if(tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
|
||||||
rotation = 90;
|
return 0;
|
||||||
break;
|
toCheck = v + new Vector2Int(1, 1);
|
||||||
case GenTile.Position.TOP_LEFT:
|
if(tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
|
||||||
rotation = 0;
|
return 90;
|
||||||
break;
|
toCheck = v + new Vector2Int(-1, 1);
|
||||||
case GenTile.Position.TOP_RIGHT:
|
if(tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
|
||||||
rotation = 270;
|
return 180;
|
||||||
break;
|
toCheck = v + new Vector2Int(-1, -1);
|
||||||
case GenTile.Position.BOTTOM_RIGHT:
|
if(tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
|
||||||
rotation = 180;
|
return 270;
|
||||||
break;
|
break;
|
||||||
}
|
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) {
|
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) {
|
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 ) {
|
switch ( neighbourDoors ) {
|
||||||
case 1:
|
case 1:
|
||||||
return ExtendedTileType.DoorOuter;
|
return ExtendedTileType.DoorOuter;
|
||||||
|
|
Loading…
Add table
Reference in a new issue