Merge remote-tracking branch 'origin/PiegamesDev'
This commit is contained in:
commit
ff9e0a4597
5 changed files with 235 additions and 114 deletions
|
@ -127,11 +127,13 @@ 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);
|
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++ ) {
|
||||||
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 +141,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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] = 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)
|
||||||
throw new NotSupportedException("Paths should not have any doors");
|
throw new NotSupportedException("Paths should not have any doors");
|
||||||
|
|
|
@ -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>();
|
||||||
|
@ -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);
|
||||||
|
|
42
Assets/Scripts/Generation/GenTile.cs
Normal file
42
Assets/Scripts/Generation/GenTile.cs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class GenTile
|
||||||
|
{
|
||||||
|
public enum Position
|
||||||
|
{
|
||||||
|
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 Position position;
|
||||||
|
|
||||||
|
public GenTile()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenTile(Room.TileType type)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenTile(Room.TileType type, Position position)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Position GetPosition(int xMode, int yMode) {
|
||||||
|
return (Position) ((xMode + 1) + (yMode + 1) * 3);
|
||||||
|
}
|
||||||
|
}
|
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,58 +11,53 @@ public class GenerationProcessor {
|
||||||
this.prefabs = prefabs;
|
this.prefabs = prefabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameObject ProcessRoom(Dictionary<Vector2Int, Room.TileType> d) {
|
public GameObject ProcessRoom(Dictionary<Vector2Int, GenTile> tiles) {
|
||||||
GameObject root = new GameObject {
|
GameObject root = new GameObject {
|
||||||
name = "Room"
|
name = "Room"
|
||||||
};
|
};
|
||||||
foreach ( Vector2Int v in d.Keys ) {
|
foreach ( Vector2Int v in tiles.Keys ) {
|
||||||
bool left = false;
|
ExtendedTileType type = ExtendedTileType.Ground;
|
||||||
bool top = false;
|
int rotation = 0;
|
||||||
bool right = false;
|
switch ( tiles[v].type ) {
|
||||||
bool bottom = false;
|
|
||||||
// left bound
|
|
||||||
if ( d.ContainsKey(v + new Vector2Int(-1, 0)) ) {
|
|
||||||
if ( d[v + new Vector2Int(-1, 0)] == d[v] ) {
|
|
||||||
left = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// top bound
|
|
||||||
if ( d.ContainsKey(v + new Vector2Int(0, 1)) ) {
|
|
||||||
if ( d[v + new Vector2Int(0, 1)] == d[v] ) {
|
|
||||||
top = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// right bound
|
|
||||||
if ( d.ContainsKey(v + new Vector2Int(1, 0)) ) {
|
|
||||||
if ( d[v + new Vector2Int(1, 0)] == d[v] ) {
|
|
||||||
right = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// bottom bound
|
|
||||||
if ( d.ContainsKey(v + new Vector2Int(0, -1)) ) {
|
|
||||||
if ( d[v + new Vector2Int(0, -1)] == d[v] ) {
|
|
||||||
bottom = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ExtendedTileType type = ExtendedTileType.Ground;
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
// ^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~
|
|
||||||
//
|
|
||||||
// *** W A R N I N G B A D C O D E A H E A D ! ! ! ***
|
|
||||||
// __________________________________________________________________________
|
|
||||||
//
|
|
||||||
// DON'T WATCH, UNLESS YOU WANT TO GET TRAUMATIZED!
|
|
||||||
//
|
|
||||||
// ^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~^~!~
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
switch ( d[v] ) {
|
|
||||||
case Room.TileType.WALL:
|
case Room.TileType.WALL:
|
||||||
type = ExtendedTileType.BorderSingle;
|
type = getCorrectWallType(tiles, v);
|
||||||
if ( top && left && d.ContainsKey(v + new Vector2Int(-1, -1)) || top && right && d.ContainsKey(v + new Vector2Int(1, -1)) || right && bottom && d.ContainsKey(v + new Vector2Int(1, 1)) || left && bottom && d.ContainsKey(v + new Vector2Int(-1, 1)) ) {
|
switch (type)
|
||||||
type = ExtendedTileType.BorderOuter;
|
{
|
||||||
} else if ( top && left || top && right || right && bottom || left && bottom ) {
|
case ExtendedTileType.BorderSingle:
|
||||||
type = ExtendedTileType.BorderInner;
|
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;
|
||||||
|
case ExtendedTileType.BorderInner:
|
||||||
|
switch (tiles[v].position)
|
||||||
|
{
|
||||||
|
case GenTile.Position.BOTTOM_LEFT:
|
||||||
|
rotation = 0;
|
||||||
|
break;
|
||||||
|
case GenTile.Position.TOP_LEFT:
|
||||||
|
rotation = 90;
|
||||||
|
break;
|
||||||
|
case GenTile.Position.TOP_RIGHT:
|
||||||
|
rotation = 180;
|
||||||
|
break;
|
||||||
|
case GenTile.Position.BOTTOM_RIGHT:
|
||||||
|
rotation = 270;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Room.TileType.GROUND:
|
case Room.TileType.GROUND:
|
||||||
type = ExtendedTileType.Ground;
|
type = ExtendedTileType.Ground;
|
||||||
|
@ -71,68 +66,137 @@ public class GenerationProcessor {
|
||||||
type = ExtendedTileType.Door;
|
type = ExtendedTileType.Door;
|
||||||
break;
|
break;
|
||||||
case Room.TileType.ROCK:
|
case Room.TileType.ROCK:
|
||||||
type = ExtendedTileType.Rock;
|
type = getCorrectRockType(tiles, v);
|
||||||
if ( top && !right && !left && !bottom ) {
|
|
||||||
type = ExtendedTileType.RockU;
|
|
||||||
}
|
|
||||||
if ( left && !right && !bottom && !top ) {
|
|
||||||
type = ExtendedTileType.RockL;
|
|
||||||
}
|
|
||||||
if ( right && !bottom && !left && !top ) {
|
|
||||||
type = ExtendedTileType.RockR;
|
|
||||||
}
|
|
||||||
if ( bottom && !right && !left && !top ) {
|
|
||||||
type = ExtendedTileType.RockD;
|
|
||||||
}
|
|
||||||
if ( left && top && !bottom && !right ) {
|
|
||||||
type = ExtendedTileType.RockLU;
|
|
||||||
}
|
|
||||||
if ( left && right && !top && !bottom ) {
|
|
||||||
type = ExtendedTileType.RockLR;
|
|
||||||
}
|
|
||||||
if ( left && bottom && !right && !top ) {
|
|
||||||
type = ExtendedTileType.RockLD;
|
|
||||||
}
|
|
||||||
if ( top && right && !left && !bottom ) {
|
|
||||||
type = ExtendedTileType.RockUR;
|
|
||||||
}
|
|
||||||
if ( top && bottom && !left && !right ) {
|
|
||||||
type = ExtendedTileType.RockUD;
|
|
||||||
}
|
|
||||||
if ( right && bottom && !top && !left ) {
|
|
||||||
type = ExtendedTileType.RockRD;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( left && top && bottom && !right ) {
|
|
||||||
type = ExtendedTileType.RockLUD;
|
|
||||||
}
|
|
||||||
if ( left && top && right && !bottom ) {
|
|
||||||
type = ExtendedTileType.RockLUR;
|
|
||||||
}
|
|
||||||
if ( top && right && bottom && !left ) {
|
|
||||||
type = ExtendedTileType.RockURD;
|
|
||||||
}
|
|
||||||
if ( left && right && bottom && !top ) {
|
|
||||||
type = ExtendedTileType.RockLRD;
|
|
||||||
}
|
|
||||||
if ( left && top && right && bottom ) {
|
|
||||||
type = ExtendedTileType.RockLURD;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateGOFromType(v, type, root);
|
CreateGOFromType(v, rotation, type, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GameObject CreateGOFromType(Vector2 v, ExtendedTileType t, GameObject root) {
|
private GameObject CreateGOFromType(Vector2 v, int rotation, ExtendedTileType t, GameObject root) {
|
||||||
GameObject tmp = null;
|
GameObject tmp = null;
|
||||||
if ( prefabs.ContainsKey(t) && root != null ) {
|
if ( prefabs.ContainsKey(t) && root != null ) {
|
||||||
tmp = GameObject.Instantiate(prefabs[t], root.transform);
|
tmp = Object.Instantiate(prefabs[t], root.transform);
|
||||||
tmp.transform.position = v;
|
tmp.transform.position = v;
|
||||||
|
tmp.transform.Rotate(new Vector3(0, 0, rotation));
|
||||||
}
|
}
|
||||||
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){
|
||||||
|
int groundNumber = CountSpecificNeighbours(tiles, position, Room.TileType.GROUND);
|
||||||
|
switch(groundNumber){
|
||||||
|
case 0:
|
||||||
|
return ExtendedTileType.BorderInner;
|
||||||
|
case 2:
|
||||||
|
return ExtendedTileType.BorderOuter;
|
||||||
|
default:
|
||||||
|
return ExtendedTileType.BorderSingle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExtendedTileType getCorrectRockType(Dictionary<Vector2Int, GenTile> tiles, Vector2Int position){
|
||||||
|
|
||||||
|
ExtendedTileType type = ExtendedTileType.Rock;
|
||||||
|
|
||||||
|
bool left = false;
|
||||||
|
bool top = false;
|
||||||
|
bool right = false;
|
||||||
|
bool bottom = false;
|
||||||
|
|
||||||
|
Vector2Int toCheck = position + new Vector2Int(0, -1);
|
||||||
|
if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.ROCK)
|
||||||
|
bottom = true;
|
||||||
|
toCheck = position + new Vector2Int(-1, 0);
|
||||||
|
if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.ROCK)
|
||||||
|
left = true;
|
||||||
|
toCheck = position + new Vector2Int(0, 1);
|
||||||
|
if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.ROCK)
|
||||||
|
top = true;
|
||||||
|
toCheck = position + new Vector2Int(1, 0);
|
||||||
|
if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.ROCK)
|
||||||
|
right = true;
|
||||||
|
|
||||||
|
if (top && !right && !left && !bottom)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockU;
|
||||||
|
}
|
||||||
|
if (left && !right && !bottom && !top)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockL;
|
||||||
|
}
|
||||||
|
if (right && !bottom && !left && !top)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockR;
|
||||||
|
}
|
||||||
|
if (bottom && !right && !left && !top)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockD;
|
||||||
|
}
|
||||||
|
if (left && top && !bottom && !right)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockLU;
|
||||||
|
}
|
||||||
|
if (left && right && !top && !bottom)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockLR;
|
||||||
|
}
|
||||||
|
if (left && bottom && !right && !top)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockLD;
|
||||||
|
}
|
||||||
|
if (top && right && !left && !bottom)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockUR;
|
||||||
|
}
|
||||||
|
if (top && bottom && !left && !right)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockUD;
|
||||||
|
}
|
||||||
|
if (right && bottom && !top && !left)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockRD;
|
||||||
|
}
|
||||||
|
if (left && top && bottom && !right)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockLUD;
|
||||||
|
}
|
||||||
|
if (left && top && right && !bottom)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockLUR;
|
||||||
|
}
|
||||||
|
if (top && right && bottom && !left)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockURD;
|
||||||
|
}
|
||||||
|
if (left && right && bottom && !top)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockLRD;
|
||||||
|
}
|
||||||
|
if (left && top && right && bottom)
|
||||||
|
{
|
||||||
|
return ExtendedTileType.RockLURD;
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue