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 { CreateWall(currentCell, neighbor, direction); } } else { CreateWall(currentCell, null, direction); } }
void CreatePassageInSameRoom(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction) { MazePassage mazePassage = Instantiate(mazePassPrefab); mazePassage.Initialise(_cell, _otherCell, _direction); mazePassage = Instantiate(mazePassPrefab); mazePassage.Initialise(_otherCell, _cell, _direction.GetOpposite()); }
private void Move(mazeDirection direction) { mazeCellEdge edge = currentCell.GetEdge(direction); if (edge is mazePassage) { SetLocation(edge.otherCell); } }
public virtual void Initialize(mazeCell cell, mazeCell otherCell, mazeDirection direction) { this.cell = cell; this.otherCell = otherCell; this.direction = direction; cell.SetEdge(direction, this); transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
private void CreateWall(mazeCell cell, mazeCell otherCell, mazeDirection direction) { mazeWall wall = Instantiate(wallPrefabs[Random.Range(0, wallPrefabs.Length)]) as mazeWall; wall.Initialize(cell, otherCell, direction); if (otherCell != null) { wall = Instantiate(wallPrefabs[Random.Range(0, wallPrefabs.Length)]) as mazeWall; wall.Initialize(otherCell, cell, direction.GetOpposite()); } }
public virtual void Initialise(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction) { this.cell = _cell; this.otherCell = _otherCell; this.direction = _direction; transform.parent = _cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = _direction.ToRotation(); //Cell should know about the edge too, Smart edge yayy _cell.SetEdge(this, _direction); }
void CreateWall(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction) { MazeWall mazeWall = Instantiate(mazeWallPrefabs[Random.Range(0, mazeWallPrefabs.Length)]) as MazeWall; mazeWall.Initialise(_cell, _otherCell, _direction); if (_otherCell != null) { mazeWall = Instantiate(mazeWallPrefabs[Random.Range(0, mazeWallPrefabs.Length)]) as MazeWall; mazeWall.Initialise(_otherCell, _cell, _direction.GetOpposite()); } }
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()); }
void DoNextGenerationStep(List <MazeCell> _activeCells) { // newest cell index int currentIndex = ChooseIndex(_activeCells.Count); MazeCell currentCell = _activeCells [currentIndex]; if (currentCell.isFullyInitialized()) { _activeCells.RemoveAt(currentIndex); return; } IntVector2 currentCoords = currentCell.coordinates; mazeDirection nextDirection = currentCell.RandomUninitializedDirection; IntVector2 nextCellCoords = currentCoords + nextDirection.ToIntVector2(); if (isCoordInRange(nextCellCoords)) { MazeCell neighbourCell = GetCell(nextCellCoords); // Check if cell already or not if (neighbourCell == null) { // i.e. cell doesn't exists neighbourCell = CreateCell(nextCellCoords); CreatePassage(currentCell, neighbourCell, nextDirection); _activeCells.Add(neighbourCell); } else if (currentCell.room == neighbourCell.room && expandRooms) { CreatePassageInSameRoom(currentCell, neighbourCell, nextDirection); } else { CreateWall(currentCell, neighbourCell, nextDirection); } } else { //Create wall CreateWall(currentCell, null, nextDirection); } }
public override void Initialize(mazeCell primary, mazeCell other, mazeDirection direction) { base.Initialize(primary, other, direction); if (OtherSideOfDoor != null) { isMirrored = true; hinge.localScale = new Vector3(-1f, 1f, 1f); Vector3 p = hinge.localPosition; p.x = -p.x; hinge.localPosition = p; } for (int i = 0; i < transform.childCount; i++) { Transform child = transform.GetChild(i); if (child != hinge) { child.GetComponent <Renderer>().material = cell.room.settings.wallMaterial; } } }
public override void Initialise(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction) { base.Initialise(_cell, _otherCell, _direction); this.isOpen = false; if (OtherSideDoor != null) { hinge.localScale = new Vector3(-1f, 1f, 1f); Vector3 hingePos = hinge.localPosition; hingePos.x = -hingePos.x; hinge.localPosition = hingePos; } for (int i = 0; i < transform.childCount; i++) { Transform doorTransform = transform.GetChild(i); if (doorTransform != hinge) { doorTransform.GetComponent <Renderer> ().material = _cell.room.setting.wallMaterial; } } }
void CreatePassage(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction) { MazePassage prefabPass = Random.value < doorProbability ? mazeDoorPrefab : mazePassPrefab; MazePassage mazePassage = Instantiate(prefabPass) as MazePassage; mazePassage.Initialise(_cell, _otherCell, _direction); if (mazePassage is MazeDoor) { //Create a new room, excluding the last index _otherCell.SetRoom((CreateRoom(_cell.room.settingIndex))); } else { //initialize with the ongoing room _otherCell.SetRoom(_cell.room); } mazePassage = Instantiate(prefabPass) as MazePassage; mazePassage.Initialise(_otherCell, _cell, _direction.GetOpposite()); }
public MazeCellEdge GetEdge(mazeDirection _direction) { return(edges [(int)_direction]); }
public static mazeDirection GetNextCounterclockwise(this mazeDirection direction) { return((mazeDirection)(((int)direction + Count - 1) % Count)); }
//pass in the direction we want and get the vector2 representation of it public static Vector2Int ToIntVector2(this mazeDirection direction) { return(vectors[(int)direction]); }
public void SetEdge(mazeDirection direction, mazeCellEdge edge) { edges[(int)direction] = edge; initializedEdgeCount += 1; }
public void SetEdge(MazeCellEdge _edge, mazeDirection _direction) { edges[(int)_direction] = _edge; initializedEdges++; }
public static mazeDirection GetOpposite(this mazeDirection dir) { return(opposites [(int)dir]); }
public override void Initialize(mazeCell cell, mazeCell otherCell, mazeDirection direction) { base.Initialize(cell, otherCell, direction); //wall.GetComponent<Renderer>().material = cell.room.settings.wallMaterial; }
public override void Initialise(MazeCell _cell, MazeCell _otherCell, mazeDirection _direction) { base.Initialise(_cell, _otherCell, _direction); transform.GetChild(0).GetComponent <Renderer> ().material = _cell.room.setting.wallMaterial; }
public static IntVector2 ToIntVector2(this mazeDirection dir) { return(vectors [(int)dir]); }
private void Look(mazeDirection direction) { transform.localRotation = direction.ToRotation(); currentDirection = direction; }
public static Quaternion ToRotation(this mazeDirection dir) { return(rotations [(int)dir]); }
public mazeCellEdge GetEdge(mazeDirection direction) { return(edges[(int)direction]); }