Exemplo n.º 1
0
 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;
         }
     }
 }
Exemplo n.º 2
0
    //checks if the cell already exists, if not adds it to the list
    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;
        Vector2Int    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 if (currentCell.room.settingsIndex == neighbor.room.settingsIndex)
            {
                CreatePassageInSameRoom(currentCell, neighbor, direction);
            }
            else
            {
                CreateWall(currentCell, neighbor, direction);
            }
        }
        else
        {
            CreateWall(currentCell, null, direction);
        }
    }
Exemplo n.º 3
0
 public override void Initialize(mazeCell cell, mazeCell otherCell, mazeDirection direction)
 {
     base.Initialize(cell, otherCell, direction);
     //wall.GetComponent<Renderer>().material = cell.room.settings.wallMaterial;
 }
Exemplo n.º 4
0
 public void Add(mazeCell cell)
 {
     cell.room = this;
     cells.Add(cell);
 }
 //Get cell in directions
 mazeCell returnCellInDir(mazeCell _cell, direction _dir)
 {
     foreach (cellLabel _cl in _cell.adjacentCells)
     {
         if (_cl.dir == _dir)
         {
             return _cl.cell;
         }
     }
     return _cell;
 }
    // Calculate a bias value based upon adjoining cells.
    float calculateDynamicBias(mazeCell _cell)
    {

        float _bias = 0;
        mazeCell temp;
        int hCount = 0;
        int vCount = 0;
        float hDecimal, vDecimal;

        #region Get Count
        foreach (cellLabel cL in _cell.adjacentCells)
        {
            switch (cL.dir)
            {
                case direction.LEFT:
                    if (cL.cell.wallLeft == false)
                    {
                        hCount++;
                        for (int i = 1; i < _stats.dBPathLength; i++)
                        {
                            temp = returnCellInDir(cL.cell, direction.LEFT);
                            if (temp != cL.cell && !temp.wallLeft)
                            {
                                hCount++;
                            }
                        }
                    }


                    break;
                case direction.RIGHT:
                    if (cL.cell.wallRight == false)
                    {
                        hCount++;
                        for (int i = 1; i < _stats.dBPathLength; i++)
                        {
                            temp = returnCellInDir(cL.cell, direction.RIGHT);
                            if (temp != cL.cell && !temp.wallRight)
                            {
                                hCount++;
                            }
                        }
                    }

                    break;
                case direction.UP:
                    if (cL.cell.wallUp == false)
                    {
                        vCount++;
                        for (int i = 1; i < _stats.dBPathLength; i++)
                        {
                            temp = returnCellInDir(cL.cell, direction.UP);
                            if (temp != cL.cell && !temp.wallUp)
                            {
                                vCount++;
                            }
                        }
                    }

                    break;
                case direction.DOWN:
                    if (cL.cell.wallDown == false)
                    {
                        vCount++;
                        for (int i = 1; i < _stats.dBPathLength; i++)
                        {
                            temp = returnCellInDir(cL.cell, direction.DOWN);
                            if (temp != cL.cell && !temp.wallDown)
                            {
                                vCount++;
                            }
                        }
                    }
                    break;
            }

        }
        #endregion
        
        //Turn count variables into a value between -1 and 1.
        hDecimal = (float)hCount / (float)_stats.dBPathLength;
        vDecimal = (float)vCount / (float)_stats.dBPathLength;
        _bias = (hDecimal - vDecimal) / 2.0f;
        //Map onto the curve
        _bias = evaluateCurve(_bias);

        return _bias;
    }
    //Function that removes the walls between the cell passed in, and the neighbour in the direction passed in.
    public void neighbourRemove(mazeCell _cell, direction _dir)
    {
        foreach (cellLabel cL in _cell.adjacentCells)
        {
            if (cL.dir == _dir)
            {
                switch (cL.dir)
                {
                    case direction.LEFT:

                        _cell.wallLeft = false;
                        cL.cell.wallRight = false;

                        break;
                    case direction.RIGHT:
                        cL.cell.wallLeft = false;
                        _cell.wallRight = false;

                        break;
                    case direction.UP:
                        cL.cell.wallDown = false;
                        _cell.wallUp = false;

                        break;
                    case direction.DOWN:
                        cL.cell.wallUp = false;
                        _cell.wallDown = false;

                        break;
                }
            }
        }
    }
    //Set variables in cells and remove the selected wall objects
    public void neighbourRemoveObject(mazeCell _cell, direction _dir)
    {
        bool temp = false;
        foreach (cellLabel cL in _cell.adjacentCells)
        {
            if (cL.dir == _dir)
            {
                switch (cL.dir)
                {
                    case direction.LEFT:

                        cL.cell.wallRight = false;
                        GameObject.DestroyImmediate(cL.cell.goWallRight);
                        cL.cell.canConnect = temp;
                        _cell.wallLeft = false;
                        GameObject.DestroyImmediate(_cell.goWallLeft);
                        _cell.canConnect = temp;
                        _cell.inMaze = true;
                        cL.cell.inMaze = true;


                        break;
                    case direction.RIGHT:

                        cL.cell.wallLeft = false;
                        GameObject.DestroyImmediate(cL.cell.goWallLeft);
                        cL.cell.canConnect = temp;
                        _cell.wallRight = false;
                        GameObject.DestroyImmediate(_cell.goWallRight);
                        _cell.canConnect = temp;
                        _cell.inMaze = true;
                        cL.cell.inMaze = true;


                        break;
                    case direction.UP:

                        cL.cell.wallDown = false;
                        GameObject.DestroyImmediate(cL.cell.goWallDown);
                        cL.cell.canConnect = temp;
                        _cell.wallUp = false;
                        GameObject.DestroyImmediate(_cell.goWallUp);
                        _cell.canConnect = temp;
                        _cell.inMaze = true;
                        cL.cell.inMaze = true;

                        break;
                    case direction.DOWN:

                        cL.cell.wallUp = false;
                        GameObject.DestroyImmediate(cL.cell.goWallUp);
                        cL.cell.canConnect = temp;
                        _cell.wallDown = false;
                        GameObject.DestroyImmediate(_cell.goWallDown);
                        _cell.canConnect = temp;
                        _cell.inMaze = true;
                        cL.cell.inMaze = true;


                        break;
                }
            }
        }
    }
    //Set variables and remove wall objects for the cells connected to the door
    private void designateDoorways(mazeCell _cell, direction _dir)
    {
        bool setConnection = true;
        foreach (cellLabel cL in _cell.adjacentCells)
        {
            if (cL.dir == _dir)
            {
                switch (cL.dir)
                {
                    case direction.LEFT:

                        cL.cell.wallRight = false;
                        GameObject.DestroyImmediate(cL.cell.goWallRight);
                        cL.cell.canConnect = setConnection;
                        _cell.wallLeft = false;
                        GameObject.DestroyImmediate(_cell.goWallLeft);
                        _cell.canConnect = setConnection;
                        _cell.inMaze = false;
                        cL.cell.inMaze = false;

                        break;
                    case direction.RIGHT:

                        cL.cell.wallLeft = false;
                        GameObject.DestroyImmediate(cL.cell.goWallLeft);
                        cL.cell.canConnect = setConnection;
                        _cell.wallRight = false;
                        GameObject.DestroyImmediate(_cell.goWallRight);
                        _cell.canConnect = setConnection;
                        _cell.inMaze = false;
                        cL.cell.inMaze = false;


                        break;
                    case direction.UP:

                        cL.cell.wallDown = false;
                        GameObject.DestroyImmediate(cL.cell.goWallDown);
                        cL.cell.canConnect = setConnection;
                        _cell.wallUp = false;
                        GameObject.DestroyImmediate(_cell.goWallUp);
                        _cell.canConnect = setConnection;
                        _cell.inMaze = false;
                        cL.cell.inMaze = false;

                        break;
                    case direction.DOWN:

                        cL.cell.wallUp = false;
                        GameObject.DestroyImmediate(cL.cell.goWallUp);
                        cL.cell.canConnect = setConnection;
                        _cell.wallDown = false;
                        GameObject.DestroyImmediate(_cell.goWallDown);
                        _cell.canConnect = setConnection;
                        _cell.inMaze = false;
                        cL.cell.inMaze = false;


                        break;
                }
            }
        }
    }
    //Create the wall object in the scene
    private void createWall(wallData wd, mazeCell _cell, direction _cellDir)
    {
        if (!wallDataHolder.Contains(wd))
        {
            GameObject wallObject;
            wallDataHolder.Add(wd);

            wallObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
            wallObject.GetComponent<Renderer>().material = _stats.wallMat;
            wallObject.name = ("Wall " + wd.position.x + ", " + wd.position.y);
            wallObject.transform.position = new Vector3(wd.position.x, _stats.wallHeight / 2, wd.position.y);

            if (wd.isHorizontal)
            {
                wallObject.transform.localScale = new Vector3(_stats.wallThickness, _stats.wallHeight, 1 + _stats.wallThickness);
            }
            else
            {
                wallObject.transform.localScale = new Vector3(1 + _stats.wallThickness, _stats.wallHeight, _stats.wallThickness);
            }
            wallObject.transform.parent = wallWorldHolder.transform;
            wallWorldHolder.name = "Walls";

            switch (_cellDir)
            {
                case direction.LEFT:
                    _cell.goWallRight = wallObject;
                    if (returnCellInDir(_cell, direction.RIGHT) != _cell)
                    {
                        returnCellInDir(_cell, direction.RIGHT).goWallLeft = wallObject;
                    }

                    break;
                case direction.RIGHT:
                    _cell.goWallLeft = wallObject;

                    if (returnCellInDir(_cell, direction.LEFT) != _cell)
                    {
                        returnCellInDir(_cell, direction.LEFT).goWallRight = wallObject;
                    }

                    break;
                case direction.UP:
                    _cell.goWallDown = wallObject;

                    if (returnCellInDir(_cell, direction.DOWN) != _cell)
                    {
                        returnCellInDir(_cell, direction.DOWN).goWallUp = wallObject;
                    }

                    break;
                case direction.DOWN:
                    _cell.goWallUp = wallObject;

                    if (returnCellInDir(_cell, direction.UP) != _cell)
                    {
                        returnCellInDir(_cell, direction.UP).goWallDown = wallObject;
                    }

                    break;

            }
        }
    }
 //Define the cells neighbours
 void getNeighbours(mazeCell _cell)
 {
     if (_cell.gridPos.x > 1)
     {
         _cell.adjacentCells.Add(new cellLabel() { cell = getCellAt(_cell.gridPos.x - 1, _cell.gridPos.y), dir = direction.LEFT });
     }
     if (_cell.gridPos.x < _stats.mazeDepth)
     {
         _cell.adjacentCells.Add(new cellLabel() { cell = getCellAt(_cell.gridPos.x + 1, _cell.gridPos.y), dir = direction.RIGHT });
     }
     if (_cell.gridPos.y > 1)
     {
         _cell.adjacentCells.Add(new cellLabel() { cell = getCellAt(_cell.gridPos.x, _cell.gridPos.y - 1), dir = direction.DOWN });
     }
     if (_cell.gridPos.y < _stats.mazeWidth)
     {
         _cell.adjacentCells.Add(new cellLabel() { cell = getCellAt(_cell.gridPos.x, _cell.gridPos.y + 1), dir = direction.UP });
     }
 }