1
0
Fork 0

Generation Processor Formatting

This commit is contained in:
Triceraptodactyl 2018-04-25 12:42:33 +02:00
parent e5ff478a13
commit d0f44c47b8

View file

@ -6,6 +6,7 @@ public class GenerationProcessor {
public enum ExtendedTileType {
BorderOuter, BorderInner, BorderSingle, Ground0, Ground1, Ground2, Ground3, DoorInner, DoorOuter, Rock, RockL, RockU, RockR, RockD, RockLU, RockLR, RockLD, RockUR, RockUD, RockRD, RockLURD, RockLUD, RockLUR, RockURD, RockLRD, Flag
}
Dictionary<ExtendedTileType, GameObject> prefabs;
public GenerationProcessor(Dictionary<ExtendedTileType, GameObject> prefabs) {
this.prefabs = prefabs;
@ -20,7 +21,7 @@ public class GenerationProcessor {
int rotation = 0;
switch ( tiles[v].type ) {
case Room.TileType.WALL:
type = GetCorrectWallType(tiles, v);
type = GetCorrectRockType(tiles, v);
rotation = GetCorrectWallRotation(tiles, v, type);
break;
case Room.TileType.GROUND:
@ -92,10 +93,7 @@ public class GenerationProcessor {
toCheck = v + new Vector2Int(0, 1);
if(tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
return 180;
toCheck = v + new Vector2Int(1, 0);
if(tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
return 90;
break;
case ExtendedTileType.BorderInner:
toCheck = v + new Vector2Int(1, -1);
if(tiles.ContainsKey(toCheck) && tiles[toCheck].type != Room.TileType.WALL)
@ -106,10 +104,7 @@ public class GenerationProcessor {
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 ExtendedTileType.BorderOuter:
Vector2Int toCheck1 = v + new Vector2Int(0, -1);
Vector2Int toCheck2 = v + new Vector2Int(-1, 0);
@ -121,10 +116,7 @@ public class GenerationProcessor {
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;
}
return 0;
}
@ -183,51 +175,44 @@ public class GenerationProcessor {
private ExtendedTileType GetCorrectDoorType(Dictionary<Vector2Int, GenTile> tiles, Vector2Int position) {
int neighbourDoors = 0;
Vector2Int toCheck = position + new Vector2Int(0, -1);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR )
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 )
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 )
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 )
if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR)
neighbourDoors++;
switch ( neighbourDoors ) {
case 1:
if(neighbourDoors == 1)
return ExtendedTileType.DoorOuter;
default:
return ExtendedTileType.DoorInner;
}
}
private int GetCorrectDoorRotation(ExtendedTileType type, Dictionary<Vector2Int, GenTile> tiles, Vector2Int position) {
switch ( type ) {
case ExtendedTileType.DoorOuter:
if(type == ExtendedTileType.DoorOuter) {
Vector2Int toCheck = position + new Vector2Int(0, -1);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR )
if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR)
return 270;
toCheck = position + new Vector2Int(-1, 0);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR )
if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR)
return 180;
toCheck = position + new Vector2Int(0, 1);
if ( tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR )
return 90;
toCheck = position + new Vector2Int(1, 0);
return 0;
case ExtendedTileType.DoorInner:
Vector2Int toCheckD = position + new Vector2Int(0, -1);
if ( tiles.ContainsKey(toCheckD) && tiles[toCheckD].type == Room.TileType.DOOR )
if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR)
return 90;
return 0;
}
toCheck = position + new Vector2Int(0, -1);
if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.DOOR)
return 90;
return 0;
}
public static Vector2Int GetDirectionVector(GenTile.Position p) {
switch ( p ) {
switch(p) {
case GenTile.Position.TOP:
return new Vector2Int(0, 1);
case GenTile.Position.LEFT:
@ -242,8 +227,8 @@ public class GenerationProcessor {
}
private ExtendedTileType GetRandomGroundType() {
int num = ( int ) ( UnityEngine.Random.value * 4 );
switch ( num ) {
int num = (int) (UnityEngine.Random.value * 4);
switch(num) {
case 0:
return ExtendedTileType.Ground0;
case 1: