private void CreatePassageInSameRoom(mazeCell cell, mazeCell otherCell, mazeDirection direction) { mazePassage passage = Instantiate(passagePrefab) as mazePassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(passagePrefab) as mazePassage; passage.Initialize(otherCell, cell, direction.GetOpposite()); if (cell.room != otherCell.room) { mazeRoom roomToAssimilate = otherCell.room; cell.room.Assimilate(roomToAssimilate); rooms.Remove(roomToAssimilate); Destroy(roomToAssimilate); } }
private void CreatePassage(mazeCell cell, mazeCell otherCell, mazeDirection direction) { mazePassage prefab = Random.value < doorProbability ? doorPrefab : passagePrefab; mazePassage passage = Instantiate(prefab) as mazePassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(prefab) as mazePassage; if (passage is mazeDoor) { otherCell.Initialize(CreateRoom(cell.room.settingsIndex)); } else { otherCell.Initialize(cell.room); } passage.Initialize(otherCell, cell, direction.GetOpposite()); }
//Build Maze Section Below private void buildPassage(int a, int b) { mazePassage newBlock; Transform connectedPortal; newBlock = Instantiate(passagePrefab[0]) as mazePassage; //place block allBlocks.Add(newBlock); //append array for block entrances for (int x = 0; x < newBlock.selfObject.entrances.Length; x++) { portals.Add(newBlock.selfObject.entrances [x].transform); //store all passages if (startHub) { passgeWay.Add(recentBlock.selfObject.entrances [x].transform); //store passages of newest block } } //place hub : only activates once if (!startHub) { newBlock.transform.localPosition = new Vector3(0f, 0f, 0f); blockCoordinates.Add(newBlock.transform.localPosition); rndPosition = Random.Range(0, portals.Count); //select random passage from previous block pickDirection = Random.Range(0, 4); direction = newBlock.selfObject.entrances [pickDirection].transform.rotation; //store rotation quanterion using rndposition to select passage. hubBlock = newBlock; } else { if (b == 0) //initiate new passageway { rndPosition = Random.Range(0, portals.Count); //select random passage from previous block nextSpot = portals [rndPosition]; //position of previous block facing the same direction pickDirection = Random.Range(0, 4); direction = nextSpot.transform.rotation; //store rotation quanterion using rndposition to select passage. newBlock.transform.localPosition = nextSpot.position; if (direction.eulerAngles.y == 0) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x + 1, 0f, newBlock.transform.position.z); for (int i = 0; i < blockCoordinates.Count; i++) { if (blockCoordinates [i] == newBlock.transform.localPosition) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x + 2, 0f, newBlock.transform.position.z); i = 0; } } connectedPortal = newBlock.selfObject.entrances [2].transform; portals.Remove(connectedPortal); } if (direction.eulerAngles.y == 90 || direction.eulerAngles.y == -270) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x, 0f, newBlock.transform.position.z - 1); for (int i = 0; i < blockCoordinates.Count; i++) { if (blockCoordinates [i] == newBlock.transform.localPosition) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x, 0f, newBlock.transform.position.z - 2); i = 0; } } connectedPortal = newBlock.selfObject.entrances [1].transform; portals.Remove(connectedPortal); } if (direction.eulerAngles.y == 180 || direction.eulerAngles.y == -180) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x - 1, 0f, newBlock.transform.position.z); for (int i = 0; i < blockCoordinates.Count; i++) { if (blockCoordinates [i] == newBlock.transform.localPosition) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x - 2, 0f, newBlock.transform.position.z); i = 0; } } connectedPortal = newBlock.selfObject.entrances [0].transform; portals.Remove(connectedPortal); } if (direction.eulerAngles.y == 270 || direction.eulerAngles.y == -90) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x, 0f, newBlock.transform.position.z + 1); for (int i = 0; i < blockCoordinates.Count; i++) { if (blockCoordinates [i] == newBlock.transform.localPosition) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x, 0f, newBlock.transform.position.z + 2); i = 0; } } connectedPortal = newBlock.selfObject.entrances [3].transform; portals.Remove(connectedPortal); } blockCoordinates.Add(newBlock.transform.localPosition); portals.Remove(nextSpot); } else //continue passageway { if (direction.eulerAngles.y == 0) { nextSpot = passgeWay [0]; //position of previous block facing the same direction newBlock.transform.localPosition = nextSpot.position; newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x + 1, 0f, newBlock.transform.position.z); for (int i = 0; i < blockCoordinates.Count; i++) { if (blockCoordinates [i] == newBlock.transform.localPosition) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x + 2, 0f, newBlock.transform.position.z); i = 0; } } connectedPortal = newBlock.selfObject.entrances [2].transform; portals.Remove(connectedPortal); } if (direction.eulerAngles.y == 90 || direction.eulerAngles.y == -270) { nextSpot = passgeWay [3]; newBlock.transform.localPosition = nextSpot.position; newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x, 0f, newBlock.transform.position.z - 1); for (int i = 0; i < blockCoordinates.Count; i++) { if (blockCoordinates [i] == newBlock.transform.localPosition) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x, 0f, newBlock.transform.position.z - 2); i = 0; } } connectedPortal = newBlock.selfObject.entrances [3].transform; portals.Remove(connectedPortal); } if (direction.eulerAngles.y == 180 || direction.eulerAngles.y == -180) { nextSpot = passgeWay [2]; newBlock.transform.localPosition = nextSpot.position; newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x - 1, 0f, newBlock.transform.position.z); for (int i = 0; i < blockCoordinates.Count; i++) { if (blockCoordinates [i] == newBlock.transform.localPosition) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x - 2, 0f, newBlock.transform.position.z); i = 0; } } connectedPortal = newBlock.selfObject.entrances [0].transform; portals.Remove(connectedPortal); } if (direction.eulerAngles.y == 270 || direction.eulerAngles.y == -90) { nextSpot = passgeWay [1]; newBlock.transform.localPosition = nextSpot.position; newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x, 0f, newBlock.transform.position.z + 1); for (int i = 0; i < blockCoordinates.Count; i++) { if (blockCoordinates [i] == newBlock.transform.localPosition) { newBlock.transform.localPosition = new Vector3(newBlock.transform.position.x, 0f, newBlock.transform.position.z + 2); i = 0; } } connectedPortal = newBlock.selfObject.entrances [1].transform; portals.Remove(connectedPortal); } blockCoordinates.Add(newBlock.transform.localPosition); portals.Remove(recentBlock.selfObject.entrances[pickDirection].transform); } } if (startHub) { passgeWay.RemoveRange(0, passgeWay.Count); } recentBlock = newBlock; passages.Add(newBlock.transform); startHub = true; }