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 {
|
||||
|
||||
[SerializeField]
|
||||
GameObject playerPrefab;
|
||||
|
||||
|
||||
[SerializeField]
|
||||
private Room start;
|
||||
private Room finish;
|
||||
|
||||
|
@ -57,13 +55,20 @@ public class GameController : MonoBehaviour {
|
|||
GameObject RockLRD;
|
||||
|
||||
private Dictionary<GenerationProcessor.ExtendedTileType, GameObject> genPrefabs;
|
||||
|
||||
[Space(10)]
|
||||
[Header("References")]
|
||||
[SerializeField]
|
||||
private GameObject ui;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject cam;
|
||||
|
||||
[SerializeField]
|
||||
GameObject playerPrefab;
|
||||
|
||||
[SerializeField]
|
||||
GameObject mapRoot;
|
||||
|
||||
private bool engineInitDone;
|
||||
private Player player;
|
||||
public static GameController instance;
|
||||
|
@ -77,28 +82,29 @@ public class GameController : MonoBehaviour {
|
|||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
genPrefabs = new Dictionary<GenerationProcessor.ExtendedTileType, GameObject>();
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderOuter, BorderOuter);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderInner, BorderInner);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.BorderSingle, BorderSingle);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.Rock, Rock);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockL, RockL);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockU, RockU);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockR, RockR);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockD, RockD);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLU, RockLU);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLR, RockLR);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLD, RockLD);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLURD, RockLURD);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockRD, RockRD);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockUR, RockUR);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockUD, RockUD);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLUD, RockLUD);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLUR, RockLUR);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockURD, RockURD);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.RockLRD, RockLRD);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.Ground, Ground);
|
||||
genPrefabs.Add(GenerationProcessor.ExtendedTileType.Door, Door);
|
||||
genPrefabs = new Dictionary<GenerationProcessor.ExtendedTileType, GameObject> {
|
||||
{ GenerationProcessor.ExtendedTileType.BorderOuter, BorderOuter },
|
||||
{ GenerationProcessor.ExtendedTileType.BorderInner, BorderInner },
|
||||
{ GenerationProcessor.ExtendedTileType.BorderSingle, BorderSingle },
|
||||
{ GenerationProcessor.ExtendedTileType.Rock, Rock },
|
||||
{ GenerationProcessor.ExtendedTileType.RockL, RockL },
|
||||
{ GenerationProcessor.ExtendedTileType.RockU, RockU },
|
||||
{ GenerationProcessor.ExtendedTileType.RockR, RockR },
|
||||
{ GenerationProcessor.ExtendedTileType.RockD, RockD },
|
||||
{ GenerationProcessor.ExtendedTileType.RockLU, RockLU },
|
||||
{ GenerationProcessor.ExtendedTileType.RockLR, RockLR },
|
||||
{ GenerationProcessor.ExtendedTileType.RockLD, RockLD },
|
||||
{ GenerationProcessor.ExtendedTileType.RockLURD, RockLURD },
|
||||
{ GenerationProcessor.ExtendedTileType.RockRD, RockRD },
|
||||
{ GenerationProcessor.ExtendedTileType.RockUR, RockUR },
|
||||
{ GenerationProcessor.ExtendedTileType.RockUD, RockUD },
|
||||
{ GenerationProcessor.ExtendedTileType.RockLUD, RockLUD },
|
||||
{ GenerationProcessor.ExtendedTileType.RockLUR, RockLUR },
|
||||
{ GenerationProcessor.ExtendedTileType.RockURD, RockURD },
|
||||
{ GenerationProcessor.ExtendedTileType.RockLRD, RockLRD },
|
||||
{ GenerationProcessor.ExtendedTileType.Ground, Ground },
|
||||
{ GenerationProcessor.ExtendedTileType.Door, Door }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -142,6 +148,24 @@ public class GameController : MonoBehaviour {
|
|||
}
|
||||
|
||||
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);
|
||||
start.SetObjective(goal);
|
||||
start.OnPlayerEnter(player);
|
||||
|
@ -149,10 +173,6 @@ public class GameController : MonoBehaviour {
|
|||
cam.GetComponent<CameraControl>().SetFollow(player.gameObject);
|
||||
}
|
||||
|
||||
private void Starting() {
|
||||
|
||||
}
|
||||
|
||||
private void Running() {
|
||||
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public class DungeonGenerator {
|
|||
goto outer;
|
||||
E.Add(new GenEdge(r1, r2));
|
||||
}
|
||||
outer:
|
||||
outer:;
|
||||
}
|
||||
F.Add(root);
|
||||
Q.Remove(root);
|
||||
|
|
|
@ -11,36 +11,36 @@ public class GenerationProcessor {
|
|||
this.prefabs = prefabs;
|
||||
}
|
||||
|
||||
public GameObject ProcessRoom(Dictionary<Vector2, Room.TileType> d) {
|
||||
public GameObject ProcessRoom(Dictionary<Vector2Int, Room.TileType> d) {
|
||||
GameObject root = new GameObject {
|
||||
name = "Room"
|
||||
};
|
||||
foreach ( Vector2 v in d.Keys ) {
|
||||
foreach ( Vector2Int v in d.Keys ) {
|
||||
bool left = false;
|
||||
bool top = false;
|
||||
bool right = false;
|
||||
bool bottom = false;
|
||||
// left bound
|
||||
if ( d.ContainsKey(v + new Vector2(-1, 0)) ) {
|
||||
if ( d[v + new Vector2(-1, 0)] == d[v] ) {
|
||||
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 Vector2(0, 1)) ) {
|
||||
if ( d[v + new Vector2(0, 1)] == d[v] ) {
|
||||
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 Vector2(1, 0)) ) {
|
||||
if ( d[v + new Vector2(1, 0)] == d[v] ) {
|
||||
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 Vector2(0, -1)) ) {
|
||||
if ( d[v + new Vector2(0, -1)] == d[v] ) {
|
||||
if ( d.ContainsKey(v + new Vector2Int(0, -1)) ) {
|
||||
if ( d[v + new Vector2Int(0, -1)] == d[v] ) {
|
||||
bottom = true;
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class GenerationProcessor {
|
|||
switch ( d[v] ) {
|
||||
case Room.TileType.WALL:
|
||||
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;
|
||||
} else if ( top && left || top && right || right && bottom || left && bottom ) {
|
||||
type = ExtendedTileType.BorderInner;
|
||||
|
|
Loading…
Add table
Reference in a new issue