1
0
Fork 0

Rotation for straight wall

This commit is contained in:
Piegames 2018-04-22 21:40:02 +02:00
parent b13a13cfde
commit ede4f74a3a
4 changed files with 55 additions and 15 deletions

View file

@ -127,7 +127,9 @@ public class DungeonGenerator {
foreach ( GenRoom r in rooms ) { foreach ( GenRoom r in rooms ) {
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++ ) {
r.tiles.Add(new Vector2Int(x1, y1), new GenTile(Room.TileType.WALL)); int xMode = (x1 == r.bounds.x) ? -1 : (x1 == r.bounds.x + r.bounds.width - 1) ? 1 : 0;
int yMode = (y1 == r.bounds.y) ? -1 : (y1 == r.bounds.y + r.bounds.height - 1) ? 1 : 0;
r.tiles.Add(new Vector2Int(x1, y1), new GenTile(Room.TileType.WALL, GenTile.GetPosition(xMode,yMode)));
} }
for ( int x1 = r.bounds.x + 1; x1 < r.bounds.x + r.bounds.width - 1; x1++ ) for ( int x1 = r.bounds.x + 1; x1 < r.bounds.x + r.bounds.width - 1; x1++ )
for ( int y1 = r.bounds.y + 1; y1 < r.bounds.y + r.bounds.height - 1; y1++ ) { for ( int y1 = r.bounds.y + 1; y1 < r.bounds.y + r.bounds.height - 1; y1++ ) {
@ -150,17 +152,19 @@ public class DungeonGenerator {
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++) for (int x2 = x1 - 1; x2 <= x1 + 1; x2++)
for (int y2 = y1 - 1; y2 <= y1 + 1; y2++) {
{ for (int y2 = y1 - 1; y2 <= y1 + 1; y2++)
{
Vector2Int pos2 = new Vector2Int(x2, y2); Vector2Int pos2 = new Vector2Int(x2, y2);
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));
} }
}
} }
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");

View file

@ -4,7 +4,7 @@ using UnityEngine;
public class GenRoom { public class GenRoom {
// ---Internal for generation only--- // ---Internal for generation only---
// TODO make them package protcted please // TODO make them package protected please
public RectInt bounds = new RectInt(); public RectInt bounds = new RectInt();
public HashSet<Vector2Int> doorsUp = new HashSet<Vector2Int>(); public HashSet<Vector2Int> doorsUp = new HashSet<Vector2Int>();

View file

@ -6,17 +6,37 @@ public class GenTile
{ {
public enum Position public enum Position
{ {
TOP, BOTTOM, LEFT, RIGHT, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT TOP_LEFT = 0,
TOP = 1,
TOP_RIGHT = 2,
LEFT = 3,
CENTER = 4,
RIGHT = 5,
BOTTOM_LEFT = 6,
BOTTOM = 7,
BOTTOM_RIGHT = 8
} }
public Room.TileType type; public Room.TileType type;
public Position position; public Position position;
public GenTile() public GenTile()
{ {
}
public GenTile(Room.TileType type)
{
this.type = type;
}
public GenTile(Room.TileType type, Position position)
{
this.type = type;
this.position = position;
} }
public GenTile(Room.TileType type) { public static Position GetPosition(int xMode, int yMode) {
this.type = type; return (Position) ((xMode + 1) + (yMode + 1) * 3);
} }
} }

View file

@ -68,6 +68,22 @@ public class GenerationProcessor {
type = ExtendedTileType.BorderInner; type = ExtendedTileType.BorderInner;
} else { } else {
// BorderSingle // BorderSingle
if (tiles[v].position != null) {
switch (tiles[v].position) {
case GenTile.Position.BOTTOM:
rotation = 0;
break;
case GenTile.Position.LEFT:
rotation = 90;
break;
case GenTile.Position.TOP:
rotation = 180;
break;
case GenTile.Position.RIGHT:
rotation = 270;
break;
}
}
} }
break; break;
case Room.TileType.GROUND: case Room.TileType.GROUND: