Ejemplo n.º 1
0
    //checks if the cell is in a 1x1 corridor
    private bool CellTooNarrow(MazeCell cell)
    {
        bool NS = cell.GetEdge(MazeDirection.North) is MazeWall && cell.GetEdge(MazeDirection.South) is MazeWall;
        bool EW = cell.GetEdge(MazeDirection.East) is MazeWall && cell.GetEdge(MazeDirection.West) is MazeWall;

        return(NS || EW);
    }
Ejemplo n.º 2
0
    private void Move(MazeDirection direction)
    {
        MazeCellEdge edge = currentCell.GetEdge(direction);

        if (edge is MazePassage)
        {
            SetLocation(edge.otherCell);
        }
    }
Ejemplo n.º 3
0
    private void PlaceExitDoor()
    {
        while (true)
        {
            MazeCell rcell = cells[Random.Range(0, size.x), Random.Range(0, size.z)];
            for (int i = 0; i < MazeDirections.Count; i++)
            {
                MazeDirection dir  = MazeDirection.North + i;
                MazeCellEdge  edge = rcell.GetEdge(dir);
                if (edge is MazeWall)
                {
                    rcell.DestroyEdge(dir);
                    Vector2i coordinates = rcell.coordinates + dir.ToVector2i();
                    if (ContainsCoordinates(coordinates))
                    {
                        exitDoor = CreateChangeStageDoor(rcell, GetCell(coordinates), dir, 1);
                    }
                    else
                    {
                        exitDoor = CreateChangeStageDoor(rcell, null, dir, 1);
                    }

                    return;
                }
            }
        }
    }
Ejemplo n.º 4
0
    public IEnumerator Generate()
    {
        WaitForSeconds delay    = new WaitForSeconds(generationStepDelay);
        int            cooldown = 0;

        cells = new MazeCell[size.x, size.z];
        List <MazeCell> activeCells = new List <MazeCell>();

        DoFirstGenerationStep(activeCells);

        while (activeCells.Count > 0)
        {
            if (cooldown > generationStepDelay_multiplier && generationStepDelay_multiplier != -1)
            {
                cooldown = 0;
                yield return(delay);
            }
            cooldown++;
            DoNextGenerationStep(activeCells);
        }

        for (int i = 0; i < 4; i++)
        {
            if (!start.GetEdge((MazeDirection)i).haswall)
            {
                start_direction = (MazeDirection)i;
            }
        }

        finish.gameObject.transform.FindChild("Quad").GetComponent <MeshRenderer> ().material = red;
        finish.gameObject.name = "FinishCell";
    }
Ejemplo n.º 5
0
    public void MoveDirection(MazeDirection direction)
    {       // If it is possible for the player to move the specified direction
        // from the last cell in player's route, the cell in that direction from
        // the last cell in player's route is added to the route.
        MazeCell cellToMoveFrom = GetDestinationCell();

        MazeCellEdge edge = cellToMoveFrom.GetEdge(direction);

        //Debug.Log(string.Format("Move:{0} from {1} to {2}", direction, cellToMoveFrom.name, edge.otherCell.name));
        if (edge is MazePassage)
        {
            if (cellToMoveFrom == edge.otherCell)
            {
                MoveToCell(edge.cell);
            }
            else if (cellToMoveFrom == edge.cell)
            {
                MoveToCell(edge.otherCell);
            }
            else
            {
                Debug.LogError(string.Format("Move:{0} from {1} to {2}", direction, cellToMoveFrom.name, edge.otherCell.name));
            }
        }
    }
Ejemplo n.º 6
0
    //Checks if the cell is in a dead end or a corner
    private bool CellinDeadEndOrCorner(MazeCell cell)
    {
        //check the numbe of walls surrounding the cell
        int numWalls = 0;

        MazeDirection[] directions = new MazeDirection[4] {
            MazeDirection.North, MazeDirection.East, MazeDirection.South, MazeDirection.West
        };
        for (int i = 0; i < 4; i++)
        {
            if (cell.GetEdge(directions[i]) is MazeWall)
            {
                ++numWalls;
            }
        }

        //If the cell has 3 walls, it's a dead end
        if (numWalls == 3)
        {
            return(true);
        }

        //If the cell has 2 walls, but they aren't opposite each other, it's in a corner
        if (numWalls == 2 && !CellTooNarrow(cell))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 7
0
    private void TryMove(MazeDirection direction)
    {
        MazeCellEdge edge = currentCell.GetEdge(direction);

        if (edge is MazePassage)
        {
            if (edge is MazeDoor && !(edge as MazeDoor).IsOpened)
            {
                return;
            }
            if (edge.otherCell.role != "Empty")
            {
                return;
            }
            EnterCell(edge.otherCell, direction);
        }
    }
Ejemplo n.º 8
0
    private IEnumerator GenerateChestsInRoom(MazeRoom room, int number)
    {
        int             chestsGenerated = 0;
        List <MazeCell> activeCells     = new List <MazeCell>(room.Cells);

        while (chestsGenerated < number)
        {
            if (chests.Count % 10 == 0)
            {
                yield return(false);
            }

            if (activeCells.Count == 0)
            {
                break;
            }

            MazeCell randCell = activeCells[Random.Range(0, activeCells.Count)];
            activeCells.Remove(randCell);
            MazePassage passage = null;
            if (randCell.IsFree)
            {
                int passageCount = 0;
                for (int i = 0; i < 4; i++)
                {
                    MazeCellEdge edge = randCell.GetEdge(i);
                    if (edge is MazePassage)
                    {
                        passage = edge as MazePassage;
                        passageCount++;
                        if (passageCount > 1)
                        {
                            break;
                        }
                    }
                }

                if (passageCount > 1)
                {
                    continue;
                }

                randCell.RegisterEntity();

                Container chest = GameObject.Instantiate(chestPrefab) as Container;
                chest.transform.parent = transform;

                chest.transform.localPosition = new Vector3(randCell.coordinates.x - size.x * 0.5f + 0.5f,
                                                            transform.position.y,
                                                            randCell.coordinates.z - size.z * 0.5f + 0.5f);
                chest.transform.localRotation = passage.direction.ToRotation();

                chestsGenerated++;

                chests.Add(chest);
            }
        }
    }
Ejemplo n.º 9
0
    private void Move(MazeDirection direction)
    {
        MazeCellEdge edge = curCell.GetEdge(direction);

        if (edge is MazePath)
        {
            SetLocation(edge.neighCell);
        }
    }
Ejemplo n.º 10
0
    //moves the stand's location based on the players cordinates
    private void Move(MazeDirection direction)
    {
        MazeCellEdge edge = currentCell.GetEdge(direction); //Returns the edge

        if (edge is MazePassage)
        {
            SetLocationA(edge.otherCell); //Returns the cell on the other side of the door
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Movement should only happen if the edge we would cross is a passage, otherwise we're blocked.
    /// </summary>
    /// <param name="direction">Direction from player.</param>
    private void Move(MazeDirection direction)
    {
        // Declare variables.
        MazeCellEdge edge = _currentMazeCell.GetEdge(direction);

        if (edge is MazePassage)
        {
            SetLocation(edge.OtherCell);
        }
    }
Ejemplo n.º 12
0
    private bool CellNextToObject(MazeCell cell)
    {
        bool nextToObject = false;

        MazeDirection[] directions = new MazeDirection[4] {
            MazeDirection.North, MazeDirection.East, MazeDirection.South, MazeDirection.West
        };
        for (int i = 0; i < 4; i++)
        {
            if (cell.GetEdge(directions[i]).otherCell != null)
            {
                if (cell.GetEdge(directions[i]).otherCell.occupied)
                {
                    nextToObject = true;
                    break;
                }
            }
        }
        return(nextToObject);
    }
Ejemplo n.º 13
0
    private void Move(MazeDirection direction)
    {
        MazeCellEdge edge = currentCell.GetEdge(direction);

        if (edge is MazeWall)
        {
        }
        else
        {
            SetLocation(edge.OtherCell());
        }
    }
Ejemplo n.º 14
0
    private void CheckWallside(MazeCell cell, MazeDirection dir, int delta)
    {
        if (cell.GetEdge(dir + delta) is MazeWall)
        {
            if (closedTurnWallDecorPrefab != null && !cell.IsCornerInitialized(dir, delta))
            {
                cell.InitializeCorner(closedTurnWallDecorPrefab, dir, delta);
            }
            return;
        }

        if (ContainsCoordinates(cell.coordinates + (dir + delta).ToVector2i() + dir.ToVector2i()))
        {
            MazeCell otherCell = GetCell(cell.coordinates + (dir + delta).ToVector2i() + dir.ToVector2i());
            if (otherCell.GetEdge(dir - delta) is MazeWall)
            {
                if (openTurnWallDecorPrefab != null)
                {
                    if (!cell.IsCornerInitialized(dir, delta))
                    {
                        cell.InitializeCorner(openTurnWallDecorPrefab, dir, delta);
                    }

                    if (ContainsCoordinates(cell.coordinates + (dir + delta).ToVector2i()))
                    {
                        MazeCell sideCell = GetCell(cell.coordinates + (dir + delta).ToVector2i());
                        if (!sideCell.IsCornerInitialized(dir, -delta))
                        {
                            sideCell.InitializeCorner(openTurnWallDecorPrefab, dir, -delta);
                        }
                    }
                }
                return;
            }
        }

        if (ContainsCoordinates(cell.coordinates + (dir + delta).ToVector2i()))
        {
            MazeCell otherCell = GetCell(cell.coordinates + (dir + delta).ToVector2i());
            if (otherCell.GetEdge(dir) is MazeWall)
            {
                if (straightWallDecorPrefab != null && !cell.IsCornerInitialized(dir, delta))
                {
                    cell.InitializeCorner(straightWallDecorPrefab, dir, delta);
                }
                return;
            }
        }
    }
Ejemplo n.º 15
0
    private bool CellNextToDoor(MazeCell cell)
    {
        bool nextToDoor = false;

        MazeDirection[] directions = new MazeDirection[4] {
            MazeDirection.North, MazeDirection.East, MazeDirection.South, MazeDirection.West
        };
        for (int i = 0; i < 4; i++)
        {
            if (cell.GetEdge(directions[i]) is MazeDoor)
            {
                nextToDoor = true;
                break;
            }
        }
        return(nextToDoor);
    }
Ejemplo n.º 16
0
    private bool CellNextToWall(MazeCell cell, out MazeDirection wall)
    {
        MazeDirection[] directions = new MazeDirection[4] {
            MazeDirection.North, MazeDirection.East, MazeDirection.South, MazeDirection.West
        };
        for (int i = 0; i < 4; i++)
        {
            if (cell.GetEdge(directions[i]) is MazeWall)
            {
                wall = directions[i];
                return(true);
            }
        }

        wall = MazeDirection.Null;
        return(false);
    }
Ejemplo n.º 17
0
    //public void SetLocation(MazeDoor cell, bool sound)
    //{
    //    if (sound)
    //    {
    //        SetLocation(cell);
    //        return;
    //    }
    //    if (currentCell != null)
    //    {
    //        currentCell.OnPlayerExited();
    //    }
    //    currentCell = cell;
    //    transform.localPosition = cell.transform.localPosition;
    //    currentCell.OnPlayerEnteredNoSound();
    //}

    private void Move(MazeDirection direction)
    {
        MazeCellEdge edge = currentCell.GetEdge(direction);

        if (edge is MazePassage)
        {
            SetLocation(edge.otherCell);
        }
        if (edge is MazeDoor)
        {
            bool correct = maze.doorSignal((MazeDoor)edge);
            if (correct)
            {
                cd++;
            }
            //SetLocation(edge.otherCell, correct);
            done = maze.makePath(currentCell.room);
        }
    }
Ejemplo n.º 18
0
    private void DestroyMazeCellEdge(MazeCell cell, MazeDirection dir)
    {
        MazeCellEdge edge = cell.GetEdge(dir);

        Destroy(edge.gameObject);
    }
Ejemplo n.º 19
0
 private void DestroyMazeCellEdge(MazeCell cell, MazeDirection dir) {
     MazeCellEdge edge = cell.GetEdge(dir);
     Destroy(edge.gameObject);
 }