private void CreatePassageInSameRoom(MuseumCell cell, MuseumCell otherCell, CellDirection direction) { MuseumRoom room = cell.room; bool isDisplayCase = Random.value < displayCaseProbability; if (isDisplayCase) { MuseumDisplayCase displayCase = Instantiate(displayCasePrefab) as MuseumDisplayCase; displayCase.Initialize(cell, otherCell, direction); displayCase = Instantiate(displayCasePrefab) as MuseumDisplayCase; displayCase.Initialize(otherCell, cell, direction.GetOpposite()); if (paintings.Length > 0) { string paintingName = paintings[(int)Random.Range(0, paintings.Length)]; displayCase.LoadTexture(paintingName); } } else { MuseumPassage passage = Instantiate(passagePrefab) as MuseumPassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(passagePrefab) as MuseumPassage; passage.Initialize(otherCell, cell, direction.GetOpposite()); } }
public Cell MakeConnection(Cell currentCell) { List <int> randomizedCellDirections = CellDirections.GetRandomizedCellDirections; // e.g [2, 1, 0, 3] for (int i = 0; i < randomizedCellDirections.Count; i++) { // The random direction from the current cell CellDirection direction = (CellDirection)randomizedCellDirections[i]; // The neighbor cell location from the direction CellLocation nextLocation = currentCell.Location + direction.ToRelativeCellLocation(); if (CanPlaceCell(nextLocation)) { CellDirection fromDirection = direction.GetOpposite(); Cell nextCell = PlaceCell(nextLocation, fromDirection); currentCell.AddConnection(direction); // Direction that connects it to the newly generated cell currentCell.name += "_" + direction; return(nextCell); } } return(null); }
public IEnumerator GenerateBTA() { DateTime startTime = DateTime.Now; for (int x = 0; x < width; x++) { for (int z = 0; z < height; z++) { // print(String.Format("x: {0}, z: {1}", x, z)); CellLocation current_location = new CellLocation(x, z); Cell currentCell = PlaceCell(current_location); if (x == 0 && z == 0) { currentCell.Material = entryCellMaterial; entryCell = currentCell; } else if (x == height - 1 && z == width - 1) { currentCell.Material = exitCellMaterial; CellDirection exitCellDirection = GetDirectionThatLeadstoOutOfBound(currentCell); currentCell.AddConnection(exitCellDirection); exitCell = currentCell; } List <int> validDirections = new List <int>(); if (x > 0) { validDirections.Add(2); } if (z > 0) { validDirections.Add(1); } if (validDirections.Count > 0) { validDirections.Shuffle(); CellDirection selectedDirection = (CellDirection)validDirections[0]; CellLocation neighbourLocation = currentCell.Location + selectedDirection.ToRelativeCellLocation(); // print(String.Format("nx: {0}, nz: {1}", neighbourLocation.x, neighbourLocation.z)); CellDirection fromDirection = selectedDirection.GetOpposite(); currentCell.AddConnection(selectedDirection); cells[neighbourLocation.x, neighbourLocation.z].AddConnection(fromDirection); } currentLength++; cellDistances[currentCell.Location.x, currentCell.Location.z] = currentLength; activeCells.Add(currentCell); yield return(new WaitForSeconds(delay)); } } CreateCellWalls(); DateTime endTime = DateTime.Now; String totalTime = endTime.Subtract(startTime).ToString(); print("Total time taken: " + totalTime); print("Generate complete"); }
private void CreateWall(MuseumCell cell, MuseumCell otherCell, CellDirection direction) { bool hasPainting = Random.value < paintingDensity; MuseumWall wall = Instantiate(wallPrefab) as MuseumWall; wall.Initialize(cell, otherCell, direction); if (otherCell != null) { wall = Instantiate(wallPrefab) as MuseumWall; wall.Initialize(otherCell, cell, direction.GetOpposite()); } if (hasPainting) { Painting painting = Instantiate(paintingPrefab) as Painting; painting.Initialize(cell, direction); if (paintings.Length > 0) { string paintingName = paintings[(int)Random.Range(0, paintings.Length)]; painting.LoadTexture(paintingName); } } }
private void CreatePassage (MapCell cell, MapCell otherCell, CellDirection direction) { if(cell == null) return; Passage passage = Instantiate(passagePrefab) as Passage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(passagePrefab) as Passage; passage.Initialize(otherCell, cell, direction.GetOpposite()); }
private void CreatePassage(MuseumCell cell, MuseumCell otherCell, CellDirection direction) { MuseumPassage prefab = Random.value < entryProbability ? entryPrefab : passagePrefab; MuseumPassage passage = Instantiate(prefab) as MuseumPassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(prefab) as MuseumPassage; if (passage is MuseumEntry) { otherCell.Initialize(CreateMuseumRoom()); } else { otherCell.Initialize(cell.room); } passage.Initialize(otherCell, cell, direction.GetOpposite()); }
private void CreateWall (MapCell cell, MapCell otherCell, CellDirection direction) { if(cell == null) return; //create 2 walls // cell.GetEdge(direction).dest(); Wall wall = Instantiate(wallPrefab) as Wall; wall.Initialize(cell, otherCell, direction); wall.transform.localPosition += new Vector3(0, 1, 0); // wall.gameObject.layer = LayerMask.NameToLayer ("Obstacles"); if (otherCell != null) { // otherCell.GetEdge(direction.GetOpposite()).dest(); wall = Instantiate(wallPrefab) as Wall; wall.Initialize(otherCell, cell, direction.GetOpposite()); wall.transform.localPosition += new Vector3(0, 1, 0); } }