private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction) { MazePassage prefab = null; if (cell.room.cells.Count > maxRoomSize) { prefab = doorPrefab; } else { prefab = Random.value < doorProbability ? doorPrefab : passagePrefab; } MazePassage passage = Instantiate(prefab, this.transform) as MazePassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(prefab, this.transform) as MazePassage; if (passage is MazeDoor) { otherCell.Initialize(CreateRoom(cell.room.settingsIndex)); } else { otherCell.Initialize(cell.room); } passage.Initialize(otherCell, cell, direction.GetOpposite()); }
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 (cell.room != otherCell.room && otherCell.room != null) { MazeRoom roomToAssimilate = otherCell.room; cell.room.Assimilate(roomToAssimilate); rooms.Remove(roomToAssimilate); Destroy(roomToAssimilate); } if (passage is MazeDoor) { otherCell.Initialize(CreateRoom(cell.room.settingsIndex)); } else { otherCell.Initialize(cell.room); } passage.Initialize(otherCell, cell, direction.GetOpposite()); }
private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction) { MazePassage prefab = Random.value < doorProbability ? doorPrefab : passagePrefab; //if(prefab == passagePrefab) //{ // prefab = Random.value < ennemyProbability ? ennemyPrefab : passagePrefab; //} MazePassage passage = Instantiate(prefab) as MazePassage; passage.transform.localScale = passage.transform.localScale * scale; passage.Initialize(cell, otherCell, direction); passage = Instantiate(prefab) as MazePassage; passage.transform.localScale = passage.transform.localScale * scale; if (passage is MazeDoor) { otherCell.Initialize(CreateRoom(cell.room.settingsIndex)); } else { otherCell.Initialize(cell.room); } passage.Initialize(otherCell, cell, direction.GetOpposite()); }
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); Vector3 localScale = new Vector3(1, 1, 1); if (passage is MazeDoor) { passage.transform.localScale = localScale; } passage = Instantiate(prefab) as MazePassage; // create room different from the one of cell ... if (passage is MazeDoor) { passage.transform.localScale = localScale; otherCell.Initialize(CreateRoom(cell.room.settingsIndex)); } // or add next cell to same room else { otherCell.Initialize(cell.room); } passage.Initialize(otherCell, cell, direction.GetOpposite()); }
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()); }
private void DoFirstGenerationStep(List <MazeCell> activeCells) { MazeCell newCell = CreateCell(RandomCoordinates); newCell.Initialize(CreateRoom(-1)); activeCells.Add(newCell); }
private void DoFirstGenerationStep(List <MazeCell> activeCells, Transform mapHolder) { MazeCell newCell = CreateCell(RandomCoordinates, mapHolder); newCell.Initialize(CreateRoom(-1), false, useShaderMaterials); activeCells.Add(newCell); }
private void DoFirstGenerationStep(List <MazeCell> activeCells) { MazeCell newCell = CreateCell(RandomCoordinates, 0, cellPrefab); newCell.Initialize(0); activeCells.Add(newCell); }
void CreatePassage(MazeCell thisCell, MazeCell thatCell, MazeDirection direction) { MazePassage prefab = Random.value < doorProbabilty ? doorPrefab : passagePrefab; MazePassage passage = Instantiate(prefab) as MazePassage; passage.Initialize(thisCell, thatCell, direction); passage = Instantiate(prefab) as MazePassage; if (passage is MazeDoor) { thatCell.Initialize(CreateRoom(thisCell.room.roomID)); } else { thatCell.Initialize(thisCell.room); } passage.Initialize(thatCell, thisCell, direction.GetOposite()); }
private void CreatePassage(MazeCell c1, MazeCell c2, MazeDirection direction) { var passagePrefab = passageSelector.PickRandomPassage(); var passage = Instantiate <MazePassage>(passagePrefab); if (passage is MazeDoor) { c2.Initialize(CreateRoom()); } else { c2.Initialize(c1.room); } passage.Initialize(c1, c2, direction); passage = Instantiate <MazePassage>(passagePrefab); passage.Initialize(c2, c1, direction.GetOpposite()); }
private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction) { MazePassage prefab = Random.value < doorProbability ? mazeDoorPrefab : 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()); }
void CreatePassageInSameRoom(MazeCell thisCell, MazeCell thatCell, MazeDirection direction) { MazePassage passage = Instantiate(passagePrefab) as MazePassage; passage.Initialize(thisCell, thatCell, direction); passage = Instantiate(passagePrefab) as MazePassage; thatCell.Initialize(thisCell.room); }
private void CreatePassage(MazeCell parentCell, MazeCell neighbourCell, MazeDirection direction) { MazePassage prefab = Random.value < doorProbability ? doorPrefab : passagePrefab; MazePassage passage = Instantiate(prefab); passage.Initialize(parentCell, neighbourCell, direction); passage = Instantiate(prefab); if (passage is MazeDoor) { neighbourCell.Initialize(CreateRoom(parentCell.room.settingsIndex)); } else { neighbourCell.Initialize(parentCell.room); } passage.Initialize(neighbourCell, parentCell, direction.GetOpposite()); }
/// <summary> /// Set a random start point. /// </summary> /// <param name="activeCells">Active cells.</param> private void DoFirstGenerationStep(ICollection <MazeCell> activeCells) { // Declare variables. MazeCell newMazeCell = CreateMazeCell(RandomCoordinates); // Create a new room with first cell. newMazeCell.Initialize(CreateRoom(-1)); activeCells.Add(newMazeCell); }
private void SetCellProperties(IntVector2 coordinates, MazeCell newCell) { cells [coordinates.x, coordinates.z] = newCell; newCell.coordinates = coordinates; newCell.settingsIndex = Random.Range(0, cellSettings.Length); newCell.name = "Maze Cell " + coordinates.x + ", " + coordinates.z; newCell.transform.parent = transform; newCell.transform.localPosition = new Vector3(coordinates.x - size.x * 0.5f + 0.5f, 0f, coordinates.z - size.z * 0.5f + 0.5f); newCell.Initialize(cellSettings [newCell.settingsIndex]); }
private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction) { //Debug.Log("CreatePassage " + cell.name + ", " + otherCell.name + ", " + direction.ToString()); MazePassage prefab = (Random.value < doorProbability) ? doorPrefab : passagePrefab; // 0.1 = 10% MazePassage passage = Instantiate <MazePassage>(prefab); passage.Initialize(cell, otherCell, direction); passage = Instantiate <MazePassage>(prefab); // is 2nd needed? if yes then set pos.z = 0.475 if (passage is MazeDoor) { otherCell.Initialize(CreateRoom(cell.room.settingsIndex)); } else { otherCell.Initialize(cell.room); } passage.Initialize(otherCell, cell, direction.GetOpposite()); }
private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction) { bool createDoor = randomGenerator.NextDouble() < DoorProbability; if (createDoor) { MazePassage door = Instantiate(DoorPrefab) as MazePassage; door.Initialize(cell, otherCell, direction); MazePassage passage = Instantiate(PassagePrefab); passage.Initialize(otherCell, cell, direction.GetOpposite()); otherCell.Initialize(CreateRoom(cell.Room.settingsIndex)); } else { MazePassage passage = Instantiate(PassagePrefab) as MazePassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(PassagePrefab) as MazePassage; otherCell.Initialize(cell.Room); passage.Initialize(otherCell, cell, direction.GetOpposite()); } }
private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction) { bool createDecor = Random.value < cell.room.settings.decorProbability ? true : false; if (otherCell.coordinates.x == playerCoordinates.x && otherCell.coordinates.z == playerCoordinates.z) { createDecor = false; } MazePassage prefab = Random.value < doorProbability ? doorPrefab[Random.Range(0, doorPrefab.Length)] : passagePrefab; MazePassage passage = Instantiate(prefab, cell.transform.position, direction.ToRotation()) as MazePassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(prefab) as MazePassage; if (passage is MazeDoor) { otherCell.Initialize(CreateRoom(cell.room.settingsIndex), false, useShaderMaterials); } else { otherCell.Initialize(cell.room, createDecor, useShaderMaterials); } passage.Initialize(otherCell, cell, direction.GetOpposite()); }
/// <summary> /// Simply instantiate their respective prefabs and initialize them, once for both cells. /// </summary> /// <param name="mazeCell">Current cell point.</param> /// <param name="otherMazeCell">Neighbour cell point.</param> /// <param name="mazeDirection">Direction of the passage.</param> private void CreatePassage(MazeCell mazeCell, MazeCell otherMazeCell, MazeDirection mazeDirection) { // Place a door or a passageway. MazePassage prefab = Random.value < _mazeDoorProbability ? _mazeDoorPrefab : _mazePassagePrefab; MazePassage passage = Instantiate(prefab); passage.Initialize(mazeCell, otherMazeCell, mazeDirection); passage = Instantiate(prefab); // Check whether a door has been placed. // If so, the other cell is the first of a new room. // If not, it belongs to the same room as the previous cell. otherMazeCell.Initialize(passage is MazeDoor ? CreateRoom(mazeCell.Room.IndexOfSettings) : mazeCell.Room); passage.Initialize(otherMazeCell, mazeCell, mazeDirection.GetOpposite()); }
public IEnumerator Generate(float generationRate) { WaitForSeconds delay = new WaitForSeconds(generationRate); cells = new MazeCell[size.x, size.y]; List <MazeCell> activeCells = new List <MazeCell>(); MazeCell firstCell = CreateCell(RandomCoordinates); firstCell.Initialize(CreateRoom(-1)); activeCells.Add(firstCell); while (activeCells.Count > 0) { yield return(delay); ContinuousGeneration(activeCells); } //for (int i = 0; i < rooms.Count; i++) // rooms [i].Hide (); }
// generate the whole maze public void StartMazeCreation() { cells = new MazeCell[size.x, size.z]; // list of all the cells that are still not yet fully initialized List <MazeCell> uninitializedCells = new List <MazeCell>(); MazeCell newCell = CreateCell(startPoint); newCell.Initialize(CreateRoom(-1)); uninitializedCells.Add(newCell); while (uninitializedCells.Count > 0) { GenerateNextStep(uninitializedCells); } // completed maze CleanseWalls(); CreatePuzzleRoom(); Debug.Log("donemaze, " + rooms.Count); CreateExit(); }
// make two cells have passages towards each other private void CreatePassage(MazeCell firstCell, MazeCell secondCell, MazeDirection direction) { // use perlin noise to calculate where arches should be float generatedNoise = Mathf.PerlinNoise((firstCell.coordinates.x * secondCell.coordinates.x) / (float)mazeGenerationNumber, (firstCell.coordinates.z * secondCell.coordinates.z) / (float)mazeGenerationNumber); MazePassage prefabType; if (generatedNoise < 0.2) { prefabType = archPrefab; } else { prefabType = passagePrefab; } // instantiate it once for each cell MazePassage passage = Instantiate(prefabType) as MazePassage; passage.Initialize(firstCell, secondCell, direction); passage = Instantiate(prefabType) as MazePassage; // create passage between two rooms if (passage is MazeArch) { secondCell.Initialize(CreateRoom(firstCell.room.settingsIndex)); } else { secondCell.Initialize(firstCell.room); } passage.Initialize(secondCell, firstCell, direction.GetOpposite()); /*GameObject newPassage; * Vector3 newPassagePos = new Vector3(0, 0, 0); * Quaternion newPassageRot = new Quaternion(0f, 0f, 0f, 0f); * if (generatedNoise < 0.2){ * newPassage = (GameObject) PhotonNetwork.Instantiate("Archway", newPassagePos, newPassageRot, 0); * } * else{ * newPassage = (GameObject) PhotonNetwork.Instantiate("MazePassage", newPassagePos, newPassageRot, 0); * } * MazePassage passage = newPassage.GetComponent<MazePassage>(); * passage.Initialize(firstCell, secondCell, direction); * * if (generatedNoise < 0.2){ * newPassage = (GameObject) PhotonNetwork.Instantiate("Archway", newPassagePos, newPassageRot, 0); * } * else{ * newPassage = (GameObject) PhotonNetwork.Instantiate("MazePassage", newPassagePos, newPassageRot, 0); * } * * passage = newPassage.GetComponent<MazePassage>(); * // create passage between two rooms * if (passage is MazeArch){ * secondCell.Initialize(CreateRoom(firstCell.room.settingsIndex)); * } * else{ * secondCell.Initialize(firstCell.room); * } * * passage.Initialize(secondCell, firstCell, direction.GetOpposite());*/ }
private void DifferentRoomAction (MazeCell cell, MazeCell otherCell, MazePassage passage) { if (passage is MazeDoor) otherCell.Initialize (CreateRoom (cell.room.settingsIndex)); else otherCell.Initialize (cell.room); }
private void CreatePassage( List <MazeCell> activeCells, MazeCell cell, MazeCell otherCell, MazeDirection direction) { // Create one of the possible passable edges from one a cell in one // room to a cell in another. MazePassage prefab = passagePrefab; // generic passage if (cell.altitude == 0 && Random.value < doorProbability) { // Possibly make a door from one room to the next prefab = doorPrefab; if (Random.value < doorProbability && CanCreateStairs(cell, otherCell, direction)) { // Instead of a door, let's try to make stairs. Stiars occupy // both cell and other cell and enforce constraints on // a low landing cell at the base of the stairs and a // high landing cell at the top of the stairs. prefab = passagePrefab; // Not a door after all! cell.accessory = Instantiate(stairsPrefab) as MazeCellAccessory; cell.accessory.cell = cell; cell.accessory.transform.parent = cell.transform; cell.accessory.transform.localPosition = Vector3.zero; cell.accessory.transform.localRotation = direction.ToRotation(); otherCell.Initialize(cell.GetRoomNumber()); IntVector2 highLandingCoordinates = otherCell.coordinates + direction.ToIntVector2(); MazeCell highLandingCell = CreateCell( highLandingCoordinates, 1, cellPrefab); activeCells.Add(highLandingCell); highLandingCell.Initialize(otherCell.GetRoomNumber() + 1); MazePassage landingPassage = Instantiate(prefab) as MazePassage; landingPassage.Initialize(otherCell, highLandingCell, direction); GameObject newColumn = Instantiate(columnPrefab) as GameObject; newColumn.transform.parent = otherCell.transform; newColumn.transform.localPosition = Vector3.zero; newColumn.transform.localRotation = direction.ToRotation(); if (null != railingColumnPrefab) { GameObject newRailingColumn = Instantiate(railingColumnPrefab) as GameObject; newRailingColumn.transform.parent = highLandingCell.transform; newRailingColumn.transform.localPosition = Vector3.zero; newRailingColumn.transform.localRotation = direction.ToRotation(); } } else { // Doors alsways change room numbers otherCell.Initialize(cell.GetRoomNumber() + 1); } } else { // This passage is neither door nor stair otherCell.Initialize(cell.GetRoomNumber()); otherCell.altitude = cell.altitude; otherCell.transform.localPosition = new Vector3(otherCell.transform.localPosition.x, otherCell.transform.localPosition.y + otherCell.altitude * 1.078f, otherCell.transform.localPosition.z); } MazePassage passage = Instantiate(prefab) as MazePassage; passage.Initialize(cell, otherCell, direction); }