1
0
Fork 0

Added GenTile

This commit is contained in:
Piegames 2018-04-22 21:22:20 +02:00
parent 2c67b3ed23
commit b13a13cfde
5 changed files with 45 additions and 10 deletions

View file

@ -127,11 +127,11 @@ public class DungeonGenerator {
foreach ( GenRoom r in rooms ) {
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++ ) {
r.tiles.Add(new Vector2Int(x1, y1), Room.TileType.WALL);
r.tiles.Add(new Vector2Int(x1, y1), new GenTile(Room.TileType.WALL));
}
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++ ) {
r.tiles[new Vector2Int(x1, y1)] = Room.TileType.GROUND;
r.tiles[new Vector2Int(x1, y1)].type = Room.TileType.GROUND;
}
allDoors.UnionWith(r.AllDoors());
foreach ( Vector2Int v in r.AllDoors() ) {
@ -139,7 +139,7 @@ public class DungeonGenerator {
if ( !r.bounds.Contains(v) )
throw new NotSupportedException("This is a bug where doors land in the wrong room. It should have been fixed.");
else
r.tiles[v] = Room.TileType.DOOR;
r.tiles[v].type = Room.TileType.DOOR;
}
}
@ -151,15 +151,15 @@ public class DungeonGenerator {
{
Vector2Int pos1 = new Vector2Int(x1, y1);
if (path.tiles.ContainsKey(pos1))
path.tiles[pos1] = Room.TileType.GROUND;
path.tiles[pos1].type = Room.TileType.GROUND;
else
path.tiles.Add(pos1, Room.TileType.GROUND);
path.tiles.Add(pos1, new GenTile(Room.TileType.GROUND));
for (int x2 = x1 - 1; x2 <= x1 + 1; x2++)
for (int y2 = y1 - 1; y2 <= y1 + 1; y2++)
{
Vector2Int pos2 = new Vector2Int(x2, y2);
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
path.tiles.Add(pos2, Room.TileType.WALL);
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL));
}
}
if (r.AllDoors().Count > 0)

View file

@ -17,7 +17,7 @@ public class GenRoom {
// The position of the anchor of the room in world space. This should be the top left corner of the room, but may be any point in the world.
public Vector2Int roomPosition;
// All positions are in room space relative to the room's anchor
public Dictionary<Vector2Int, Room.TileType> tiles = new Dictionary<Vector2Int, Room.TileType>();
public Dictionary<Vector2Int, GenTile> tiles = new Dictionary<Vector2Int, GenTile>();
public float Distance(GenRoom r) {
return Math.Abs(GetCenter().x - r.GetCenter().x) + Math.Abs(GetCenter().y - r.GetCenter().y);

View file

@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GenTile
{
public enum Position
{
TOP, BOTTOM, LEFT, RIGHT, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT
}
public Room.TileType type;
public Position position;
public GenTile()
{
}
public GenTile(Room.TileType type) {
this.type = type;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1b8dce5bdb3204011a32ee1b512a4296
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -11,7 +11,7 @@ public class GenerationProcessor {
this.prefabs = prefabs;
}
public GameObject ProcessRoom(Dictionary<Vector2Int, Room.TileType> tiles) {
public GameObject ProcessRoom(Dictionary<Vector2Int, GenTile> tiles) {
GameObject root = new GameObject {
name = "Room"
};
@ -56,7 +56,7 @@ public class GenerationProcessor {
//
// ^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~
// ---------------------------------------------------------------------------------------------------------------------------------------------
switch ( tiles[v] ) {
switch ( tiles[v].type ) {
case Room.TileType.WALL:
type = ExtendedTileType.BorderSingle;
if ( top && left && tiles.ContainsKey(v + new Vector2Int(-1, -1))
@ -66,7 +66,9 @@ public class GenerationProcessor {
type = ExtendedTileType.BorderOuter;
} else if ( top && left || top && right || right && bottom || left && bottom ) {
type = ExtendedTileType.BorderInner;
}
} else {
// BorderSingle
}
break;
case Room.TileType.GROUND:
type = ExtendedTileType.Ground;