private static void FFDiscoverMaze(IntVector2 position, MazeDirection direction, IntVector2[,] pacdotCoords) { if (pacdotCoords[position.x, position.z] != null) { //have we visited this position already? return; } //Distance is half a unit to account for sides RaycastHit2D hit = Physics2D.Raycast(position.toVector2(), direction.ToIntVector2().toVector2(), 0.5f); if (hit) { //fall back after hitting something return; } pacdotCoords[position.x, position.z] = position; //Go in all directions MazeDirection nextDir = MazeDirection.North; FFDiscoverMaze(position + nextDir.ToIntVector2(), nextDir, pacdotCoords); nextDir = MazeDirection.East; FFDiscoverMaze(position + nextDir.ToIntVector2(), nextDir, pacdotCoords); nextDir = MazeDirection.South; FFDiscoverMaze(position + nextDir.ToIntVector2(), nextDir, pacdotCoords); nextDir = MazeDirection.West; FFDiscoverMaze(position + nextDir.ToIntVector2(), nextDir, pacdotCoords); }
private void GenerateNextStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell current_cell = activeCells[currentIndex]; if (current_cell.IsFullInit) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direc = current_cell.RandomInit; IntVector2 coordinates = current_cell.coordinates + direc.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = Get_Cell(coordinates); if (neighbor == null) { neighbor = Create_Cell(coordinates); Create_Passage(current_cell, neighbor, direc); activeCells.Add(neighbor); } else { Create_Wall(current_cell, neighbor, direc); } } else { Create_Wall(current_cell, null, direc); } }
private void DoNextGenerationStep(List <MazeCell> activeCells) // huh.. nice backtracking algorithm, must use with Generate loop { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates) && GetCell(coordinates) == null) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else { CreateWall(currentCell, neighbor, direction); } } else { CreateWall(currentCell, null, direction); } }
private void DoNextGeneartionStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { if (InMiddle(coordinates)) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else { CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } } else if (JustOutMiddle(coordinates)) { CreateWall(currentCell, null, direction); } else { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if (neighbor.coordinates.x == TopMiddleCorner.x && neighbor.coordinates.z == TopMiddleCorner.z) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); } else { CreateWall(currentCell, neighbor, direction); } } } else { CreateWall(currentCell, null, direction); } }
private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { currentCell.FindAllPassages(); activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else { CreateWall(currentCell, neighbor, direction); } } else { CreateWall(currentCell, null, direction); } }
private void CreateRemainCells(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell current = activeCells[currentIndex]; if (current.isFullyInitialised) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = current.RandomUninitializedDirection; IntVector2 nextCoord = current.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(nextCoord)) { MazeCell neighbour = GetCell(nextCoord); if (neighbour == null) { neighbour = CreateCell(nextCoord); CreatePassage(current, neighbour, direction); activeCells.Add(neighbour); } else { CreateWall(current, neighbour, direction); } } else { CreateWall(current, null, direction); } }
private void DoNextGenerationStep(List <MazeCells> activeCells) { int currentIndex = activeCells.Count - 1; MazeCells currentCell = activeCells[currentIndex]; MazeDirection direction = MazeDirections.RandomValue; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCells neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else { CreateWall(currentCell, neighbor, direction); activeCells.RemoveAt(currentIndex); } } else { CreateWall(currentCell, null, direction); activeCells.RemoveAt(currentIndex); } }
//choose next cell in maze path private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; //if the cell is already used, return if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; //choose random direction IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); //choose next cell in that direction if (ContainsCoordinates(coordinates)) //if it's in the map { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) //if it's available { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else { CreateWall(currentCell, neighbor, direction); } } else //(if the space isn't in the map) { CreateWall(currentCell, null, direction); } }
private bool CanCreateStairs( MazeCell cell, MazeCell otherCell, MazeDirection direction) { // To create stairs, the strairs must have a altitude 0 low landing cell in the same // room as the stairs, and there must not be an existing cell at the location of the // future high landing cell. bool result = false; if (null != stairsPrefab && 0 == cell.altitude) { IntVector2 lowLandingCoordinates = cell.coordinates + direction.GetOpposite().ToIntVector2(); IntVector2 highLandingCoordinates = otherCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(lowLandingCoordinates) && ContainsCoordinates(highLandingCoordinates)) { MazeCell lowLandingCell = GetCell(lowLandingCoordinates); if (null != lowLandingCell && cell.GetRoomNumber() == lowLandingCell.GetRoomNumber() && null == GetCell(highLandingCoordinates)) { result = true; } } } return(result); }
//================================================================================= // DoNextGenerationStep Retrieves the current cell, checks whether it can move on // to the next cell and removes cells from the list if the move isn't possible //================================================================================= private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; //if all of a cells neighbours have been visited, removes cell from the active list if (currentCell.IsFullyInitialised) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitialisedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); //if the coordinate found in Contains coordinate is within the bounds of the maze if (ContainsCoordinates(coordinates)) { MazeCell neighbour = GetCell(coordinates); if (neighbour == null) //if the cell is empty, create a passage { neighbour = CreateCell(coordinates); //creates the cell CreatePassage(currentCell, neighbour, direction); //creates passage using the CreatePassage function activeCells.Add(neighbour); //sets the cell as active } else //if cell is occupied { CreateWall(currentCell, neighbour, direction); //creates wall using CreateWall function } } else { CreateWall(currentCell, null, direction); //creates wall using CreateWall function } }
public MazeDirection?CreateShortOrLongCut(IntVector2 playerCoords, bool isShortcut) { List <IntVector2> pathToExit = GetPathToExit(playerCoords); if (pathToExit.Count < 2) { Debug.LogError("trying to make shortcut from exit."); return(null); //this should only happen if the player is at the exit } MazeDirection?bestDirMaybe = UnconnectedNeighborWithShortestOrLongestPathToExit(playerCoords, pathToExit, isShortcut); if (bestDirMaybe == null) { return(null); } MazeDirection bestDir = bestDirMaybe.GetValueOrDefault(); IntVector2 bestNeighborChoice = playerCoords + bestDir.ToIntVector2(); IntVector2 neighborToRemove = pathToExit[1]; DestroyHallwayAndWallItsDoors(playerCoords, neighborToRemove); ReplaceWallsWithNewHallwayAndDoors(playerCoords, bestNeighborChoice, greenHallway: isShortcut, redHallway: !isShortcut); return(bestDirMaybe); }
// all other generation steps private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) // if target cell is within the maze { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) // if no neighboring cell is created { neighbor = CreateCell(coordinates); // creates cell CreatePassage(currentCell, neighbor, direction); // creates passage activeCells.Add(neighbor); // adds new cell to active cells } else // if creating a wall between two cells { CreateWall(currentCell, neighbor, direction); } } else // if attempting to create wall on the maze border { CreateWall(currentCell, null, direction); } }
private void DoNextGenerationStep( List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; Debug.Assert(currentIndex >= 0); MazeCell currentCell = activeCells [currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { if (null != cellTreePrefab && 0 == Random.Range(0, 77)) { neighbor = CreateCell(coordinates, 0, cellTreePrefab); activeCells.Add(neighbor); } else { neighbor = CreateCell(coordinates, 0, cellPrefab); activeCells.Add(neighbor); CreatePassage(activeCells, currentCell, neighbor, direction); } } else if (currentCell.GetRoomNumber() == neighbor.GetRoomNumber() && doorProbability > 0 && currentCell.altitude == neighbor.altitude) { CreatePassageInSameRoom(currentCell, neighbor, direction); } else { CreateWall(currentCell, neighbor, direction); } } else { CreateWall(currentCell, null, direction); } }
//This function will also determine if a wall should be created private void DoNextGenerationStep(List <CS_MazeCell> activeCells) { //Checks whether the coordinates are within the grid and havent already been called //Therefore checking for valid cells int currentIndex = activeCells.Count - 1; CS_MazeCell currentCell = activeCells[currentIndex]; //Tests to see if all cell edges have been initialised as either a wall or a passage //before removing it from the activecells list. This will allow the maze to be a //"Perfect" maze in which there will be no unreachable walled-off sections if (currentCell.bIsFullyRealised) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); //If the move is possible (the cell is valid) the cell will be created and added to active cells if (ContainsCoordinates(coordinates)) { //Creates a temporary cell that stores the next cell to be called CS_MazeCell neighbour = GetCell(coordinates); //If the cell hasnt been created yet (doesnt exist yet) then it is created //and a passage is created between the cells if (neighbour == null) { //Creates the cell neighbour = CreateCell(coordinates); //Creates the passage between them so its open space CreatePassage(currentCell, neighbour, direction); //Adds the neighbour to the active cells(cells created) activeCells.Add(neighbour); } //If the neighbour cell has been created or is outside the grid them it wont be created //and a wall will be created between them else { //Creates the wall in between the current cell and the neighbouring one CreateWall(currentCell, neighbour, direction); } } //otherwise if the cell isnt valid, it will be removed from active cells else { CreateWall(currentCell, null, direction); } }
/// <summary> /// Calls the current cell and checks if the move is possible, otherwise the cell will be removed from the list. /// </summary> /// <param name="activeCells">Active cells.</param> private void DoNextGenerationStep(IList <MazeCell> activeCells) { // Declare variables. int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; // Remove a cell from the active list only when all edges have been initialized. if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } // Just pick a random direction that has not yet been initialized for the current cell. MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.Coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCell neighbour = GetMazeCell(coordinates); // If we're still inside the maze, we need to check if the current cell's neighbour doesn't exist yet. if (neighbour == null) { // If so, we create it and place a passage in between them.. neighbour = CreateMazeCell(coordinates); CreatePassage(currentCell, neighbour, direction); activeCells.Add(neighbour); } // Join together adjacent rooms if they share the same settings. else if (currentCell.Room.IndexOfSettings == neighbour.Room.IndexOfSettings) { // Calls this method when two cells share a room, instead of placing a wall. CreatePassageInSameRoom(currentCell, neighbour, direction); } else { // But if the neighbor already exists, we separate them with a wall. CreateWall(currentCell, neighbour, direction); } } else { // When we would go out of the maze, we add a wall. CreateWall(currentCell, null, direction); } }
private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; MazeDirection direction = MazeDirections.RandomValue; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (this.ContainsCoordinates(coordinates) && this.GetCell(coordinates) == null) { activeCells.Add(this.CreateCell(coordinates)); } else { activeCells.RemoveAt(currentIndex); } }
private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = (activeCells.Count - 1); MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if (currentCell.room.settingsIndex == neighbor.room.settingsIndex) { CreatePassageInSameRoom(currentCell, neighbor, direction); } else { if (!hasSafe && currentCell.tag != "Hide") { CreateSafe(currentCell, neighbor, direction); hasSafe = true; safeCell = currentCell; } else { CreateWall(currentCell, neighbor, direction); } } } else { CreateWall(currentCell, null, direction); } }
private void DoNextGenerationStep(List <MazeCell> activeCells) { // Get the last active cell to try to expand from it int currentIndex = activeCells.Count - 1; //Random.Range(0,activeCells.Count); MazeCell currentCell = activeCells[currentIndex]; // Cell is already fully expanded if (currentCell.IsFullyInitialized()) { activeCells.RemoveAt(currentIndex); return; } // Create neighbor from expansion MazeDirection direction = currentCell.RandomUninitializedDirection(); IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); // It is inside the maze if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); // Doesn't already exist if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if (currentCell.room == neighbor.room && openRoom) { CreatePassageInSameRoom(currentCell, neighbor, direction); } // Already exists else { CreateWall(currentCell, neighbor, direction); } } // Outside maze else { CreateWall(currentCell, null, direction); } }
// do the next step of the maze generation private void GenerateNextStep(List <MazeCell> uninitializedCells) { int currentIndex = uninitializedCells.Count - 1; MazeCell currentCell = uninitializedCells[currentIndex]; if (currentCell.IsFullyInitialized) { uninitializedCells.RemoveAt(currentIndex); return; } // move in set directions based on input number directions MazeDirection direction = currentCell.UninitializedDirection(mazeGenerationNumber); IntVector2 coords = currentCell.coordinates + direction.ToIntVector2(); // if the coordinates are inside the maze, then... if (ContainsCoordinates(coords)) { MazeCell neighbor = GetCell(coords); // if cell not filled yet if (neighbor == null) { neighbor = CreateCell(coords); CreatePassage(currentCell, neighbor, direction); uninitializedCells.Add(neighbor); } // if the cells are in the same room else if (currentCell.room == neighbor.room) { CreateSameRoomPassage(currentCell, neighbor, direction); } // create a wall between the cells else { CreateWall(currentCell, neighbor, direction); } } // create a wall if it would go outside of the maze else { CreateWall(currentCell, null, direction); } }
/// <summary> /// Initialize one of the active cells by creating wall or other cells. /// The chosen active cell to be initialized depends of the IndexSelectionMethod. /// </summary> /// <param name="activeCells"></param> private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = GetIndexBySelectionMethod(activeCells); MazeCell currentCell = activeCells[currentIndex]; // if we initialized all edges, remove this cell from active cell if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } // Choose a random edge not initialized MazeDirection direction = currentCell.RandomUninitializedDirectionFrom(randomGenerator); IntVector2 coordinates = currentCell.Coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); // If the choosen edge has'nt cell attached create a cell with a passage if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if ((!UsingWallInSameRoom && currentCell.Room == neighbor.Room) || (MergeSameSettingRooms && currentCell.Room.settings == neighbor.Room.settings)) { CreatePassageInSameRoom(currentCell, neighbor, direction); } // Else we create a wall with the existing cell else { CreateWall(currentCell, neighbor, direction); } } else // The edge is on the limit of the maze { CreateWall(currentCell, null, direction); } }
//根据上一个创建下一个 void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; //四个方向全部初始化 if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; //基于上个cell,然后随机初始化的方向,来确定下一个cell位置(neighbor) IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); //若隔壁地板还不存在,那么默认设置为通道,可移动 if (neighbor == null) { //创建新格子,并标记当前格子和新格子的位置信息 neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if (currentCell.room.settingIndex == neighbor.room.settingIndex)//相邻的room索引相同,则合并 { CreatePassageInSameRoom(currentCell, neighbor, direction); } else//若隔壁已经有格子了就生成墙,不能移动 { CreateWall(currentCell, neighbor, direction); } } else { //边界位置就修墙。 CreateWall(currentCell, null, direction); } }
//Retrieves current cell, check if next move possible without collision, take care of removing cells from list private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; //To completely fill maze: //Only remove cell from active list when all edges initialized if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } //Only pick random direction that not yet initialized for current cell MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (containsCoordinates(coordinates)) { MazeCell neighbour = GetCell(coordinates); if (neighbour == null) { neighbour = CreateCell(coordinates); CreatePassage(currentCell, neighbour, direction); activeCells.Add(neighbour); } //else if (currentCell.room == neighbour.room) { // CreatePassageInSameRoom (currentCell, neighbour, direction); //} else { CreateWall(currentCell, neighbour, direction); } } //If occupied remove from list else { CreateWall(currentCell, null, direction); //No longer removing cell here //activeCells.RemoveAt (currentIndex); } }
private void DoNextGenerationStep(List <MazeCell> activeCells) // 17 cc : 19 { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if (currentCell.room.settingsIndex == neighbor.room.settingsIndex) // new { CreatePassageInSameRoom(currentCell, neighbor, direction); // new } else { CreateWall(currentCell, neighbor, direction); // test this //activeCells.RemoveAt(currentIndex); } } else { CreateWall(currentCell, null, direction); // and this //activeCells.RemoveAt(currentIndex); } }
private void DoNextGenerationStep(List <MazeCell> activeCells) { //int currentIndex = 0; //int currentIndex = activeCells.Count/2; int currentIndex = Mathf.Max(activeCells.Count - 4, 0); //int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if (currentCell.room.settingsIndex == neighbor.room.settingsIndex) { CreatePassageInSameRoom(currentCell, neighbor, direction); } else { CreateWall(currentCell, neighbor, direction); // No longer remove the cell here. } } else { CreateWall(currentCell, null, direction); // No longer remove the cell here. } }
private IEnumerator AnimateMovements(MazeDirection direction) { WaitForSeconds delay = new WaitForSeconds(delayAnimatedMovement); Vector3 direcitonVector = IntVector2.ToVector3(direction.ToIntVector2()); Vector3 position = transform.localPosition; float currentAngle = 0; float increment = 180f / 50f; for (float i = 0; i <= 1f; i += deltaMove) { Vector3 temporaryLocation = position; temporaryLocation.x += direcitonVector.x * i; temporaryLocation.y += (Mathf.Sin((Mathf.PI / 180) * currentAngle)) / 2; temporaryLocation.z += direcitonVector.z * i; transform.localPosition = temporaryLocation; currentAngle += increment; yield return(delay); } transform.localPosition = new Vector3(position.x + direcitonVector.x, position.y, position.z + direcitonVector.z); StopCoroutine(AnimateMovements(direction)); }
//retrieve the current cell, check whether the move is possible private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; //to prevent placing incorrect walls, we should only pick a random direction that is not yet initialized for the current cell. if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { //If we're still inside the maze, we need to check if the current cell's neightbor doesn't exist yet. MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } //If so, we create it and place a passage in between them. else if (currentCell.room.settingsIndex == neighbor.room.settingsIndex) { CreatePassageInSameRoom(currentCell, neighbor, direction); } //But if the neighbor already exists, we separate them with a wall. else { CreateWall(currentCell, neighbor, direction); } } else { CreateWall(currentCell, null, direction); } }
private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { ScaleObject(activeCells[currentIndex].gameObject, cellScale, cellScale); CreateInteracts(currentCell); CreateEnemies(currentCell); activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if (currentCell.room.settingsIndex == neighbor.room.settingsIndex) { CreatePassageInSameRoom(currentCell, neighbor, direction); } else { CreateWall(currentCell, neighbor, direction); } } else { CreateWall(currentCell, null, direction); } }
private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); if (!backtracking && numOfCells < totalNumOfCells) { BMazeManager.Instance.CreatePickup(currentCell); cellList.Remove(currentCell); backtracking = true; } return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); backtracking = false; } else { CreateWall(currentCell, neighbor, direction); } } else { CreateWall(currentCell, null, direction); } }
private void DoNextGenerationStep(List <MazeCellv2> activeCells) { int[] randomIndexArr = new int[5] { 0, Mathf.FloorToInt((activeCells.Count - 1) / 2), activeCells.Count - 1, activeCells.Count - 1, activeCells.Count - 1 }; int currentIndex = randomIndexArr[randomIndex];;//if you pick first it very different behaviour of generation MazeCellv2 currentCell = activeCells[currentIndex]; if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); if (ContainsCoordinates(coordinates)) { MazeCellv2 neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if (currentCell.room != null && (currentCell.room.settingsIndex == neighbor.room.settingsIndex)) { CreatePassageInSameRoom(currentCell, neighbor, direction); } else { CreateWall(currentCell, neighbor, direction); } } else { CreateWall(currentCell, null, direction); } }
//Continues the porocess of randomly creating cells, check wheter if the current cell is in the list, and if not then removing the cell from the list private void DoNextGenerationStep(List <MazeCell> activeCells) { int currentIndex = activeCells.Count - 1; MazeCell currentCell = activeCells[currentIndex]; //checks to see if the cell is fully Initialized if (currentCell.IsFullyInitialized) { activeCells.RemoveAt(currentIndex); return; } MazeDirection direction = currentCell.RandomUninitializedDirection; IntVector2 coordinates = currentCell.coordinates + direction.ToIntVector2(); //Instantiates a random point to start at //Checking neighboring cells, creating passages, then creating walls around the created cells if (ContainsCoordinates(coordinates)) { MazeCell neighbor = GetCell(coordinates); if (neighbor == null) { neighbor = CreateCell(coordinates); CreatePassage(currentCell, neighbor, direction); activeCells.Add(neighbor); } else if (currentCell.room.settingsIndex == neighbor.room.settingsIndex) { CreatePassageInSameRoom(currentCell, neighbor, direction); } else { CreateWall(currentCell, neighbor, direction); } } else { CreateWall(currentCell, null, direction); } }