//checks if the cell is in a 1x1 corridor private bool CellTooNarrow(MazeCell cell) { bool NS = cell.GetEdge(MazeDirection.North) is MazeWall && cell.GetEdge(MazeDirection.South) is MazeWall; bool EW = cell.GetEdge(MazeDirection.East) is MazeWall && cell.GetEdge(MazeDirection.West) is MazeWall; return(NS || EW); }
private void Move(MazeDirection direction) { MazeCellEdge edge = currentCell.GetEdge(direction); if (edge is MazePassage) { SetLocation(edge.otherCell); } }
private void PlaceExitDoor() { while (true) { MazeCell rcell = cells[Random.Range(0, size.x), Random.Range(0, size.z)]; for (int i = 0; i < MazeDirections.Count; i++) { MazeDirection dir = MazeDirection.North + i; MazeCellEdge edge = rcell.GetEdge(dir); if (edge is MazeWall) { rcell.DestroyEdge(dir); Vector2i coordinates = rcell.coordinates + dir.ToVector2i(); if (ContainsCoordinates(coordinates)) { exitDoor = CreateChangeStageDoor(rcell, GetCell(coordinates), dir, 1); } else { exitDoor = CreateChangeStageDoor(rcell, null, dir, 1); } return; } } } }
public IEnumerator Generate() { WaitForSeconds delay = new WaitForSeconds(generationStepDelay); int cooldown = 0; cells = new MazeCell[size.x, size.z]; List <MazeCell> activeCells = new List <MazeCell>(); DoFirstGenerationStep(activeCells); while (activeCells.Count > 0) { if (cooldown > generationStepDelay_multiplier && generationStepDelay_multiplier != -1) { cooldown = 0; yield return(delay); } cooldown++; DoNextGenerationStep(activeCells); } for (int i = 0; i < 4; i++) { if (!start.GetEdge((MazeDirection)i).haswall) { start_direction = (MazeDirection)i; } } finish.gameObject.transform.FindChild("Quad").GetComponent <MeshRenderer> ().material = red; finish.gameObject.name = "FinishCell"; }
public void MoveDirection(MazeDirection direction) { // If it is possible for the player to move the specified direction // from the last cell in player's route, the cell in that direction from // the last cell in player's route is added to the route. MazeCell cellToMoveFrom = GetDestinationCell(); MazeCellEdge edge = cellToMoveFrom.GetEdge(direction); //Debug.Log(string.Format("Move:{0} from {1} to {2}", direction, cellToMoveFrom.name, edge.otherCell.name)); if (edge is MazePassage) { if (cellToMoveFrom == edge.otherCell) { MoveToCell(edge.cell); } else if (cellToMoveFrom == edge.cell) { MoveToCell(edge.otherCell); } else { Debug.LogError(string.Format("Move:{0} from {1} to {2}", direction, cellToMoveFrom.name, edge.otherCell.name)); } } }
//Checks if the cell is in a dead end or a corner private bool CellinDeadEndOrCorner(MazeCell cell) { //check the numbe of walls surrounding the cell int numWalls = 0; MazeDirection[] directions = new MazeDirection[4] { MazeDirection.North, MazeDirection.East, MazeDirection.South, MazeDirection.West }; for (int i = 0; i < 4; i++) { if (cell.GetEdge(directions[i]) is MazeWall) { ++numWalls; } } //If the cell has 3 walls, it's a dead end if (numWalls == 3) { return(true); } //If the cell has 2 walls, but they aren't opposite each other, it's in a corner if (numWalls == 2 && !CellTooNarrow(cell)) { return(true); } else { return(false); } }
private void TryMove(MazeDirection direction) { MazeCellEdge edge = currentCell.GetEdge(direction); if (edge is MazePassage) { if (edge is MazeDoor && !(edge as MazeDoor).IsOpened) { return; } if (edge.otherCell.role != "Empty") { return; } EnterCell(edge.otherCell, direction); } }
private IEnumerator GenerateChestsInRoom(MazeRoom room, int number) { int chestsGenerated = 0; List <MazeCell> activeCells = new List <MazeCell>(room.Cells); while (chestsGenerated < number) { if (chests.Count % 10 == 0) { yield return(false); } if (activeCells.Count == 0) { break; } MazeCell randCell = activeCells[Random.Range(0, activeCells.Count)]; activeCells.Remove(randCell); MazePassage passage = null; if (randCell.IsFree) { int passageCount = 0; for (int i = 0; i < 4; i++) { MazeCellEdge edge = randCell.GetEdge(i); if (edge is MazePassage) { passage = edge as MazePassage; passageCount++; if (passageCount > 1) { break; } } } if (passageCount > 1) { continue; } randCell.RegisterEntity(); Container chest = GameObject.Instantiate(chestPrefab) as Container; chest.transform.parent = transform; chest.transform.localPosition = new Vector3(randCell.coordinates.x - size.x * 0.5f + 0.5f, transform.position.y, randCell.coordinates.z - size.z * 0.5f + 0.5f); chest.transform.localRotation = passage.direction.ToRotation(); chestsGenerated++; chests.Add(chest); } } }
private void Move(MazeDirection direction) { MazeCellEdge edge = curCell.GetEdge(direction); if (edge is MazePath) { SetLocation(edge.neighCell); } }
//moves the stand's location based on the players cordinates private void Move(MazeDirection direction) { MazeCellEdge edge = currentCell.GetEdge(direction); //Returns the edge if (edge is MazePassage) { SetLocationA(edge.otherCell); //Returns the cell on the other side of the door } }
/// <summary> /// Movement should only happen if the edge we would cross is a passage, otherwise we're blocked. /// </summary> /// <param name="direction">Direction from player.</param> private void Move(MazeDirection direction) { // Declare variables. MazeCellEdge edge = _currentMazeCell.GetEdge(direction); if (edge is MazePassage) { SetLocation(edge.OtherCell); } }
private bool CellNextToObject(MazeCell cell) { bool nextToObject = false; MazeDirection[] directions = new MazeDirection[4] { MazeDirection.North, MazeDirection.East, MazeDirection.South, MazeDirection.West }; for (int i = 0; i < 4; i++) { if (cell.GetEdge(directions[i]).otherCell != null) { if (cell.GetEdge(directions[i]).otherCell.occupied) { nextToObject = true; break; } } } return(nextToObject); }
private void Move(MazeDirection direction) { MazeCellEdge edge = currentCell.GetEdge(direction); if (edge is MazeWall) { } else { SetLocation(edge.OtherCell()); } }
private void CheckWallside(MazeCell cell, MazeDirection dir, int delta) { if (cell.GetEdge(dir + delta) is MazeWall) { if (closedTurnWallDecorPrefab != null && !cell.IsCornerInitialized(dir, delta)) { cell.InitializeCorner(closedTurnWallDecorPrefab, dir, delta); } return; } if (ContainsCoordinates(cell.coordinates + (dir + delta).ToVector2i() + dir.ToVector2i())) { MazeCell otherCell = GetCell(cell.coordinates + (dir + delta).ToVector2i() + dir.ToVector2i()); if (otherCell.GetEdge(dir - delta) is MazeWall) { if (openTurnWallDecorPrefab != null) { if (!cell.IsCornerInitialized(dir, delta)) { cell.InitializeCorner(openTurnWallDecorPrefab, dir, delta); } if (ContainsCoordinates(cell.coordinates + (dir + delta).ToVector2i())) { MazeCell sideCell = GetCell(cell.coordinates + (dir + delta).ToVector2i()); if (!sideCell.IsCornerInitialized(dir, -delta)) { sideCell.InitializeCorner(openTurnWallDecorPrefab, dir, -delta); } } } return; } } if (ContainsCoordinates(cell.coordinates + (dir + delta).ToVector2i())) { MazeCell otherCell = GetCell(cell.coordinates + (dir + delta).ToVector2i()); if (otherCell.GetEdge(dir) is MazeWall) { if (straightWallDecorPrefab != null && !cell.IsCornerInitialized(dir, delta)) { cell.InitializeCorner(straightWallDecorPrefab, dir, delta); } return; } } }
private bool CellNextToDoor(MazeCell cell) { bool nextToDoor = false; MazeDirection[] directions = new MazeDirection[4] { MazeDirection.North, MazeDirection.East, MazeDirection.South, MazeDirection.West }; for (int i = 0; i < 4; i++) { if (cell.GetEdge(directions[i]) is MazeDoor) { nextToDoor = true; break; } } return(nextToDoor); }
private bool CellNextToWall(MazeCell cell, out MazeDirection wall) { MazeDirection[] directions = new MazeDirection[4] { MazeDirection.North, MazeDirection.East, MazeDirection.South, MazeDirection.West }; for (int i = 0; i < 4; i++) { if (cell.GetEdge(directions[i]) is MazeWall) { wall = directions[i]; return(true); } } wall = MazeDirection.Null; return(false); }
//public void SetLocation(MazeDoor cell, bool sound) //{ // if (sound) // { // SetLocation(cell); // return; // } // if (currentCell != null) // { // currentCell.OnPlayerExited(); // } // currentCell = cell; // transform.localPosition = cell.transform.localPosition; // currentCell.OnPlayerEnteredNoSound(); //} private void Move(MazeDirection direction) { MazeCellEdge edge = currentCell.GetEdge(direction); if (edge is MazePassage) { SetLocation(edge.otherCell); } if (edge is MazeDoor) { bool correct = maze.doorSignal((MazeDoor)edge); if (correct) { cd++; } //SetLocation(edge.otherCell, correct); done = maze.makePath(currentCell.room); } }
private void DestroyMazeCellEdge(MazeCell cell, MazeDirection dir) { MazeCellEdge edge = cell.GetEdge(dir); Destroy(edge.gameObject); }