GenerationProcessor made compatible | Fix missing ; | Basic Generation
This commit is contained in:
parent
2fc0087db5
commit
87456a4787
3 changed files with 62 additions and 42 deletions
|
@ -4,10 +4,8 @@ using UnityEngine;
|
||||||
|
|
||||||
public class GameController : MonoBehaviour {
|
public class GameController : MonoBehaviour {
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
GameObject playerPrefab;
|
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
private Room start;
|
private Room start;
|
||||||
private Room finish;
|
private Room finish;
|
||||||
|
|
||||||
|
@ -57,13 +55,20 @@ public class GameController : MonoBehaviour {
|
||||||
GameObject RockLRD;
|
GameObject RockLRD;
|
||||||
|
|
||||||
private Dictionary<GenerationProcessor.ExtendedTileType, GameObject> genPrefabs;
|
private Dictionary<GenerationProcessor.ExtendedTileType, GameObject> genPrefabs;
|
||||||
|
[Space(10)]
|
||||||
|
[Header("References")]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private GameObject ui;
|
private GameObject ui;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private GameObject cam;
|
private GameObject cam;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
GameObject playerPrefab;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
GameObject mapRoot;
|
||||||
|
|
||||||
private bool engineInitDone;
|
private bool engineInitDone;
|
||||||
private Player player;
|
private Player player;
|
||||||
public static GameController instance;
|
public static GameController instance;
|
||||||
|
@ -77,28 +82,29 @@ public class GameController : MonoBehaviour {
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start () {
|
void Start () {
|
||||||
genPrefabs = new Dictionary<GenerationProcessor.ExtendedTileType, GameObject>();
|
genPrefabs = new Dictionary<GenerationProcessor.ExtendedTileType, GameObject> {
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderOuter, BorderOuter);
|
{ GenerationProcessor.ExtendedTileType.BorderOuter, BorderOuter },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderInner, BorderInner);
|
{ GenerationProcessor.ExtendedTileType.BorderInner, BorderInner },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderSingle, BorderSingle);
|
{ GenerationProcessor.ExtendedTileType.BorderSingle, BorderSingle },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.Rock, Rock);
|
{ GenerationProcessor.ExtendedTileType.Rock, Rock },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockL, RockL);
|
{ GenerationProcessor.ExtendedTileType.RockL, RockL },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockU, RockU);
|
{ GenerationProcessor.ExtendedTileType.RockU, RockU },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockR, RockR);
|
{ GenerationProcessor.ExtendedTileType.RockR, RockR },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockD, RockD);
|
{ GenerationProcessor.ExtendedTileType.RockD, RockD },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLU, RockLU);
|
{ GenerationProcessor.ExtendedTileType.RockLU, RockLU },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLR, RockLR);
|
{ GenerationProcessor.ExtendedTileType.RockLR, RockLR },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLD, RockLD);
|
{ GenerationProcessor.ExtendedTileType.RockLD, RockLD },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLURD, RockLURD);
|
{ GenerationProcessor.ExtendedTileType.RockLURD, RockLURD },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockRD, RockRD);
|
{ GenerationProcessor.ExtendedTileType.RockRD, RockRD },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockUR, RockUR);
|
{ GenerationProcessor.ExtendedTileType.RockUR, RockUR },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockUD, RockUD);
|
{ GenerationProcessor.ExtendedTileType.RockUD, RockUD },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLUD, RockLUD);
|
{ GenerationProcessor.ExtendedTileType.RockLUD, RockLUD },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLUR, RockLUR);
|
{ GenerationProcessor.ExtendedTileType.RockLUR, RockLUR },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockURD, RockURD);
|
{ GenerationProcessor.ExtendedTileType.RockURD, RockURD },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLRD, RockLRD);
|
{ GenerationProcessor.ExtendedTileType.RockLRD, RockLRD },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.Ground, Ground);
|
{ GenerationProcessor.ExtendedTileType.Ground, Ground },
|
||||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.Door, Door);
|
{ GenerationProcessor.ExtendedTileType.Door, Door }
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +148,24 @@ public class GameController : MonoBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Init() {
|
private void Init() {
|
||||||
|
// Generation
|
||||||
|
DungeonGenerator dg = new DungeonGenerator();
|
||||||
|
GenerationProcessor gp = new GenerationProcessor(genPrefabs);
|
||||||
|
dg.Generate();
|
||||||
|
GameObject goStart = gp.ProcessRoom(dg.start.tiles);
|
||||||
|
start = goStart.AddComponent<Room>();
|
||||||
|
start.transform.SetParent(mapRoot.transform);
|
||||||
|
GameObject goFinish = gp.ProcessRoom(dg.end.tiles);
|
||||||
|
finish = goFinish.AddComponent<Room>();
|
||||||
|
finish.transform.SetParent(mapRoot.transform);
|
||||||
|
foreach (GenRoom gr in dg.rooms) {
|
||||||
|
GameObject groom = gp.ProcessRoom(gr.tiles);
|
||||||
|
groom.AddComponent<Room>();
|
||||||
|
groom.transform.SetParent(mapRoot.transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Starting() {
|
||||||
StartObjective goal = new StartObjective(start, playerPrefab);
|
StartObjective goal = new StartObjective(start, playerPrefab);
|
||||||
start.SetObjective(goal);
|
start.SetObjective(goal);
|
||||||
start.OnPlayerEnter(player);
|
start.OnPlayerEnter(player);
|
||||||
|
@ -149,10 +173,6 @@ public class GameController : MonoBehaviour {
|
||||||
cam.GetComponent<CameraControl>().SetFollow(player.gameObject);
|
cam.GetComponent<CameraControl>().SetFollow(player.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Starting() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Running() {
|
private void Running() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class DungeonGenerator {
|
||||||
goto outer;
|
goto outer;
|
||||||
E.Add(new GenEdge(r1, r2));
|
E.Add(new GenEdge(r1, r2));
|
||||||
}
|
}
|
||||||
outer:
|
outer:;
|
||||||
}
|
}
|
||||||
F.Add(root);
|
F.Add(root);
|
||||||
Q.Remove(root);
|
Q.Remove(root);
|
||||||
|
|
|
@ -11,36 +11,36 @@ public class GenerationProcessor {
|
||||||
this.prefabs = prefabs;
|
this.prefabs = prefabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameObject ProcessRoom(Dictionary<Vector2, Room.TileType> d) {
|
public GameObject ProcessRoom(Dictionary<Vector2Int, Room.TileType> d) {
|
||||||
GameObject root = new GameObject {
|
GameObject root = new GameObject {
|
||||||
name = "Room"
|
name = "Room"
|
||||||
};
|
};
|
||||||
foreach ( Vector2 v in d.Keys ) {
|
foreach ( Vector2Int v in d.Keys ) {
|
||||||
bool left = false;
|
bool left = false;
|
||||||
bool top = false;
|
bool top = false;
|
||||||
bool right = false;
|
bool right = false;
|
||||||
bool bottom = false;
|
bool bottom = false;
|
||||||
// left bound
|
// left bound
|
||||||
if ( d.ContainsKey(v + new Vector2(-1, 0)) ) {
|
if ( d.ContainsKey(v + new Vector2Int(-1, 0)) ) {
|
||||||
if ( d[v + new Vector2(-1, 0)] == d[v] ) {
|
if ( d[v + new Vector2Int(-1, 0)] == d[v] ) {
|
||||||
left = true;
|
left = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// top bound
|
// top bound
|
||||||
if ( d.ContainsKey(v + new Vector2(0, 1)) ) {
|
if ( d.ContainsKey(v + new Vector2Int(0, 1)) ) {
|
||||||
if ( d[v + new Vector2(0, 1)] == d[v] ) {
|
if ( d[v + new Vector2Int(0, 1)] == d[v] ) {
|
||||||
top = true;
|
top = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// right bound
|
// right bound
|
||||||
if ( d.ContainsKey(v + new Vector2(1, 0)) ) {
|
if ( d.ContainsKey(v + new Vector2Int(1, 0)) ) {
|
||||||
if ( d[v + new Vector2(1, 0)] == d[v] ) {
|
if ( d[v + new Vector2Int(1, 0)] == d[v] ) {
|
||||||
right = true;
|
right = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// bottom bound
|
// bottom bound
|
||||||
if ( d.ContainsKey(v + new Vector2(0, -1)) ) {
|
if ( d.ContainsKey(v + new Vector2Int(0, -1)) ) {
|
||||||
if ( d[v + new Vector2(0, -1)] == d[v] ) {
|
if ( d[v + new Vector2Int(0, -1)] == d[v] ) {
|
||||||
bottom = true;
|
bottom = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public class GenerationProcessor {
|
||||||
switch ( d[v] ) {
|
switch ( d[v] ) {
|
||||||
case Room.TileType.WALL:
|
case Room.TileType.WALL:
|
||||||
type = ExtendedTileType.BorderSingle;
|
type = ExtendedTileType.BorderSingle;
|
||||||
if ( top && left && d.ContainsKey(v + new Vector2(-1, -1)) || top && right && d.ContainsKey(v + new Vector2(1, -1)) || right && bottom && d.ContainsKey(v + new Vector2(1, 1)) || left && bottom && d.ContainsKey(v + new Vector2(-1, 1)) ) {
|
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)) ) {
|
||||||
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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue