private T createPrefab <T>(IntVector2 coordinates, MazeDirection facing, MonoBehaviour type) where T : MonoBehaviour
    {
        T mazeObject = createPrefab <T>(coordinates, type);

        mazeObject.transform.Rotate(MazeDirections.ToRotation(facing).eulerAngles);
        return(mazeObject);
    }
Esempio n. 2
0
 public virtual void BuildBetween(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 = MazeDirections.GetRotation(direction);
 }
Esempio n. 3
0
    public IEnumerator Generate()
    {
        WaitForSeconds delay = new WaitForSeconds(generationStepDelay);

        cells = new MazeCell[size.x, size.z];
        IntVector2 coord = RandomCoord;         //new IntVector2(0,0);

        // TODO
        while (ContainsCoord(coord) && GetCell(coord) == null)
        {
            yield return(delay);

            CreateCell(coord);
            coord += MazeDirections.ToIntVector2(MazeDirections.RandomValue());
            //coord.x += 1;
        }
    }
Esempio n. 4
0
        /// <summary>
        /// Tests if <see cref="nodeNumber"/>, which is adjacent to <see cref="currentNode"/> is inside the maze matrix bounds at the given <see cref="direction"/>.
        /// </summary>
        /// <param name="nodeNumber">The adjacent node number of the maze matrix to test.</param>
        /// <param name="currentNode">The current node number, which is a reference point of <see cref="nodeNumber"/>.</param>
        /// <param name="direction">The direction at which the <see cref="nodeNumber"/> should be.</param>
        /// <returns>True if <see cref="nodeNumber"/> is in the given <see cref="direction"/> from <see cref="currentNode"/>. Otherwise, false.</returns>
        private bool TestRelatedLegitimacy(int nodeNumber, int currentNode, MazeDirections direction)
        {
            int MazeArea = MazeColumns * MazeRows;

            switch (direction)
            {
            case MazeDirections.NORTH:
                return(nodeNumber >= 0);

            case MazeDirections.SOUTH:
                return(nodeNumber < MazeArea);

            case MazeDirections.EAST:
                return(nodeNumber < MazeArea && nodeNumber / MazeColumns == currentNode / MazeColumns);

            case MazeDirections.WEST:
                return(nodeNumber >= 0 && nodeNumber / MazeColumns == currentNode / MazeColumns);

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
            }
        }
Esempio n. 5
0
    private IEnumerator GenerateRandomSteps()
    {
        var delay = new WaitForSeconds(0.01f);

        InitCells();
        var coord = RandomCoordinates();

        while (MazeContainsCoordinates(coord))
        {
            yield return(delay);

            CreateCell(coord);
            while (GetCell(coord) != null)
            {
                coord += MazeDirections.RandomIntVector2Direction();
                if (!MazeContainsCoordinates(coord))
                {
                    break;
                }
            }
        }
    }
Esempio n. 6
0
    private void ExpandActiveCells(List <MazeCell> activeCells)
    {
        int      index = activeCells.Count - 1;
        MazeCell cell  = activeCells[index];

        if (cell.IsFullyVisited)
        {
            activeCells.RemoveAt(index);
            return;
        }
        MazeDirection direction = cell.RandomNewDirection();
        var           newCoord  = cell.coord + MazeDirections.GetStep(direction);

        if (IsValidCoord(newCoord))
        {
            MazeCell neighbor = GetCell(newCoord);
            if (neighbor == null)
            {
                neighbor = CreateCell(newCoord);
                CreatePassage(cell, neighbor, direction);
                activeCells.Add(neighbor);
            }
            else if (cell.room.settingsIndex == neighbor.room.settingsIndex)
            {
                CreatePassageInOneRoom(cell, neighbor, direction);
            }
            else
            {
                CreateWall(cell, neighbor, direction);
            }
        }
        else
        {
            CreateWall(cell, null, direction);
        }
    }
Esempio n. 7
0
    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 + MazeDirections.ToIntVector2(direction);

        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);
        }
    }
Esempio n. 8
0
 private void Look(MazeDirection direction)
 {
     transform.localRotation = MazeDirections.GetRotation(direction);
     currentDirection        = direction;
 }
Esempio n. 9
0
        /// <summary>
        /// Adds the adjacent node of <param name="currentNode"> to the nodes <param name="queue"/>.</param>
        /// </summary>
        /// <param name="mazeMatrix">The matrix containing the queue, tracking points and given nodes.</param>
        /// <param name="queue">A reference to the integer array which represents the node queue.</param>
        /// <param name="trackingPoints">A reference to the integer array which represents the tracking points.</param>
        /// <param name="currentNode">The node which is the currently processed on in the <param name="queue">.</param>"/></param>
        /// <param name="previousNode">The previous node which was processed on in the <param name="queue">.</param></param>
        /// <param name="direction">The direction on which to check for an adjacent node.</param>
        public void EqueueNextNode(int[,] mazeMatrix, ref int[] queue, ref int[] trackingPoints, int currentNode, ref int previousNode, MazeDirections direction)
        {
            int AdjacentNode;

            switch (direction)
            {
            case MazeDirections.NORTH:
                AdjacentNode = currentNode - MazeColumns;
                break;

            case MazeDirections.SOUTH:
                AdjacentNode = currentNode + MazeColumns;
                break;

            case MazeDirections.EAST:
                AdjacentNode = currentNode + 1;
                break;

            case MazeDirections.WEST:
                AdjacentNode = currentNode - 1;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, "Enqueue: Adjacent node appears to be either invalid or out of the matrix.");
            }

            if (!TestRelatedLegitimacy(AdjacentNode, currentNode, direction))
            {
                return;
            }
            if (GetNodeValue(MazeMatrix, AdjacentNode) != (int)MazeNodeStatus.Ready)
            {
                return;
            }
            if (GetNodeValue(mazeMatrix, AdjacentNode) != (int)MazeNodeStatus.Ready)
            {
                return;
            }

            queue[previousNode]          = AdjacentNode;
            trackingPoints[previousNode] = currentNode;
            SetNodeValue(mazeMatrix, AdjacentNode, (int)MazeNodeStatus.Busy);
            previousNode++;
        }
 void GetDataFromCurrentCell(MazeCell currentCell, out MazeDirection direction, out Vector2Int neighbourCoordinates)
 {
     direction            = currentCell.RandomUninitializedDirection;
     neighbourCoordinates = MazeDirections.MakeNewCoordinates(currentCell.coordinates, direction);
     currentCell.RemoveEdge(direction);
 }
Esempio n. 11
0
 private void initMazeData()
 {
     //initialize entire array
     for (int x = 0; x < size.x; x++)
     {
         for (int z = 0; z < size.z; z++)
         {
             SetType(x, z, WallType.SolidWall);
         }
     }
     //set start and end
     if (regenerating)
     {
         SetType(end, WallType.Floor);
     }
     else
     {
         SetType(start, WallType.Floor);
     }
     //loot room at the center of maze
     for (int x = mazeSize.x - 2; x <= mazeSize.x + 2; x++)
     {
         for (int z = mazeSize.z - 2; z <= mazeSize.z + 2; z++)
         {
             if (x == mazeSize.x - 2 || x == mazeSize.x + 2 || z == mazeSize.z - 2 || z == mazeSize.z + 2)
             {
                 SetType(x, z, WallType.PermanentWall);
             }
             else
             {
                 SetType(x, z, WallType.LootRoom);
             }
         }
     }
     //randomly decide entrance to loot room
     dir = MazeDirections.randomEnum <MazeDirection>();
     if (dir == MazeDirection.South)
     {
         door.z         -= 2;
         doorEntrance.z -= 3;
     }
     else if (dir == MazeDirection.North)
     {
         door.z         += 2;
         doorEntrance.z += 3;
     }
     else if (dir == MazeDirection.West)
     {
         door.x         -= 2;
         doorEntrance.x -= 3;
     }
     else
     {
         door.x         += 2;
         doorEntrance.x += 3;
     }
     //add Treasure Chest
     if (!regenerating)
     {
         SetType(mazeSize, WallType.TreasureChest);
     }
 }