private void Start() { Subdungeon rootSubDungeon = new Subdungeon(new Rect(0, 0, rows, columns)); CreateBSP(rootSubDungeon); rootSubDungeon.CreateRooms(); boardPosFloor = new GameObject[rows, columns]; DrawRooms(rootSubDungeon); DrawCorridors(rootSubDungeon); DrawWalls(); DrawBase(); Vector3 playerPos = new Vector3(rootSubDungeon.GetRoom().xMax / 2, rootSubDungeon.GetRoom().yMax / 2, 0f); //put the player in the middle of the first room player.transform.position = playerPos; //set player position Vector3 center = new Vector3(rows / 2, columns / 2, -1f); //have the minimap render out a top down view of the center of the map minimap.transform.position = center; minimap.orthographicSize = rows / 2f; //keep size large enough that it can see the entire dungeon output playerPos.z = -9f; Darkness.transform.position = playerPos; }
public Rect GetRoom() { if (isLeaf()) { return(room); } if (left != null) { Rect leftRoom = left.GetRoom(); if (leftRoom.x != -1) { return(leftRoom); } } if (right != null) { Rect rightRoom = right.GetRoom(); if (rightRoom.x != -1) { return(rightRoom); } } return(new Rect(-1, -1, 0, 0)); // a null rectangle }
public void CreateCorridor(Subdungeon left, Subdungeon right) { //picks a random position in each room and connect those points Rect rroom = right.GetRoom(); Rect lroom = left.GetRoom(); Vector2 leftPt = new Vector2((int)Random.Range(lroom.x + 1, lroom.xMax - 1), (int)Random.Range(lroom.y + 1, lroom.yMax - 1)); Vector2 rightPt = new Vector2((int)Random.Range(rroom.x + 1, rroom.xMax - 1), (int)Random.Range(rroom.y + 1, rroom.yMax - 1)); if (leftPt.x > rightPt.x) { Vector2 temp = leftPt; leftPt = rightPt; rightPt = temp; } int w = (int)(leftPt.x - rightPt.x); //do those random points have the same width? int h = (int)(leftPt.y - rightPt.y); //do those random points have the same height? if (w != 0) { if (Random.Range(0, 1) > 2) { corridors.Add(new Rect(leftPt.x, leftPt.y, Mathf.Abs(w) + 1, 1)); if (h < 0) { corridors.Add(new Rect(rightPt.x, leftPt.y, 1, Mathf.Abs(h))); } else { corridors.Add(new Rect(rightPt.x, leftPt.y, 1, -Mathf.Abs(h))); } } else { if (h < 0) { corridors.Add(new Rect(leftPt.x, leftPt.y, 1, Mathf.Abs(h))); } else { corridors.Add(new Rect(leftPt.x, rightPt.y, 1, Mathf.Abs(h))); } corridors.Add(new Rect(leftPt.x, rightPt.y, Mathf.Abs(w) + 1, 1)); } } else { if (h < 0) { corridors.Add(new Rect((int)leftPt.x, (int)leftPt.y, 1, Mathf.Abs(h))); } else { corridors.Add(new Rect((int)rightPt.x, (int)rightPt.y, 1, Mathf.Abs(h))); } } }