Added GenTile
This commit is contained in:
parent
2c67b3ed23
commit
b13a13cfde
5 changed files with 45 additions and 10 deletions
|
@ -127,11 +127,11 @@ 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), 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 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++ ) {
|
||||||
r.tiles[new Vector2Int(x1, y1)] = Room.TileType.GROUND;
|
r.tiles[new Vector2Int(x1, y1)].type = Room.TileType.GROUND;
|
||||||
}
|
}
|
||||||
allDoors.UnionWith(r.AllDoors());
|
allDoors.UnionWith(r.AllDoors());
|
||||||
foreach ( Vector2Int v in r.AllDoors() ) {
|
foreach ( Vector2Int v in r.AllDoors() ) {
|
||||||
|
@ -139,7 +139,7 @@ public class DungeonGenerator {
|
||||||
if ( !r.bounds.Contains(v) )
|
if ( !r.bounds.Contains(v) )
|
||||||
throw new NotSupportedException("This is a bug where doors land in the wrong room. It should have been fixed.");
|
throw new NotSupportedException("This is a bug where doors land in the wrong room. It should have been fixed.");
|
||||||
else
|
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);
|
Vector2Int pos1 = new Vector2Int(x1, y1);
|
||||||
if (path.tiles.ContainsKey(pos1))
|
if (path.tiles.ContainsKey(pos1))
|
||||||
path.tiles[pos1] = Room.TileType.GROUND;
|
path.tiles[pos1].type = Room.TileType.GROUND;
|
||||||
else
|
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 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, Room.TileType.WALL);
|
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (r.AllDoors().Count > 0)
|
if (r.AllDoors().Count > 0)
|
||||||
|
|
|
@ -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.
|
// 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;
|
public Vector2Int roomPosition;
|
||||||
// All positions are in room space relative to the room's anchor
|
// 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) {
|
public float Distance(GenRoom r) {
|
||||||
return Math.Abs(GetCenter().x - r.GetCenter().x) + Math.Abs(GetCenter().y - r.GetCenter().y);
|
return Math.Abs(GetCenter().x - r.GetCenter().x) + Math.Abs(GetCenter().y - r.GetCenter().y);
|
||||||
|
|
22
Assets/Scripts/Generation/GenTile.cs
Normal file
22
Assets/Scripts/Generation/GenTile.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Generation/GenTile.cs.meta
Normal file
11
Assets/Scripts/Generation/GenTile.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1b8dce5bdb3204011a32ee1b512a4296
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -11,7 +11,7 @@ public class GenerationProcessor {
|
||||||
this.prefabs = prefabs;
|
this.prefabs = prefabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameObject ProcessRoom(Dictionary<Vector2Int, Room.TileType> tiles) {
|
public GameObject ProcessRoom(Dictionary<Vector2Int, GenTile> tiles) {
|
||||||
GameObject root = new GameObject {
|
GameObject root = new GameObject {
|
||||||
name = "Room"
|
name = "Room"
|
||||||
};
|
};
|
||||||
|
@ -56,7 +56,7 @@ public class GenerationProcessor {
|
||||||
//
|
//
|
||||||
// ^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~
|
// ^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~
|
||||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
switch ( tiles[v] ) {
|
switch ( tiles[v].type ) {
|
||||||
case Room.TileType.WALL:
|
case Room.TileType.WALL:
|
||||||
type = ExtendedTileType.BorderSingle;
|
type = ExtendedTileType.BorderSingle;
|
||||||
if ( top && left && tiles.ContainsKey(v + new Vector2Int(-1, -1))
|
if ( top && left && tiles.ContainsKey(v + new Vector2Int(-1, -1))
|
||||||
|
@ -66,7 +66,9 @@ public class GenerationProcessor {
|
||||||
type = ExtendedTileType.BorderOuter;
|
type = ExtendedTileType.BorderOuter;
|
||||||
} else if ( top && left || top && right || right && bottom || left && bottom ) {
|
} else if ( top && left || top && right || right && bottom || left && bottom ) {
|
||||||
type = ExtendedTileType.BorderInner;
|
type = ExtendedTileType.BorderInner;
|
||||||
}
|
} else {
|
||||||
|
// BorderSingle
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Room.TileType.GROUND:
|
case Room.TileType.GROUND:
|
||||||
type = ExtendedTileType.Ground;
|
type = ExtendedTileType.Ground;
|
||||||
|
|
Loading…
Add table
Reference in a new issue