Beispiel #1
0
    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 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);
        }
    }
Beispiel #3
0
    /// <summary>
    /// Simply instantiate their respective prefabs and initialize them, once for both cells.
    /// </summary>
    /// <param name="mazeCell">Current cell point.</param>
    /// <param name="otherMazeCell">Neighbour cell point.</param>
    /// <param name="mazeDirection">Direction of the passage.</param>
    private void CreatePassage(MazeCell mazeCell, MazeCell otherMazeCell, MazeDirection mazeDirection)
    {
        // Place a door or a passageway.
        MazePassage prefab  = Random.value < _mazeDoorProbability ? _mazeDoorPrefab : _mazePassagePrefab;
        MazePassage passage = Instantiate(prefab);

        passage.Initialize(mazeCell, otherMazeCell, mazeDirection);
        passage = Instantiate(prefab);

        // Check whether a door has been placed.
        // If so, the other cell is the first of a new room.
        // If not, it belongs to the same room as the previous cell.
        otherMazeCell.Initialize(passage is MazeDoor ? CreateRoom(mazeCell.Room.IndexOfSettings) : mazeCell.Room);

        passage.Initialize(otherMazeCell, mazeCell, mazeDirection.GetOpposite());
    }
        public void InitInfo(int _rMax, int _cMax)
        {
            rMax = _rMax;
            cMax = _cMax;

            roomInstance = GetComponent <MMRoomInstance>();
            pathfinding  = gameObject.AddComponent <APathfindingEdge>();


            cells = new MazeCell[rMax, cMax];

            EmptyPassage = new GameObject("EmptyPassage").AddComponent <MazePassage>();
            EmptyWall    = new GameObject("EmptyWall").AddComponent <MazeWall>();
            EmptyWall.transform.parent    = transform;
            EmptyPassage.transform.parent = transform;
        }
Beispiel #5
0
    private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction)
    {
        MazePassage prefab  = Random.Range(0.0f, 1.0f) < doorProbability ? doorPrefab : passagePrefab;
        MazePassage passage = Instantiate(prefab) as MazePassage;

        passage.BuildBetween(cell, otherCell, direction);
        if (prefab is MazeDoor)
        {
            otherCell.InitWithRoom(CreateRoom(cell.room.settingsIndex));
        }
        else
        {
            otherCell.InitWithRoom(cell.room);
        }
        passage = Instantiate(prefab) as MazePassage;
        passage.BuildBetween(otherCell, cell, direction.GetOpposite());
    }
    void CreatePassage(MazeCell thisCell, MazeCell thatCell, MazeDirection direction)
    {
        MazePassage prefab  = Random.value < doorProbabilty ? doorPrefab : passagePrefab;
        MazePassage passage = Instantiate(prefab) as MazePassage;

        passage.Initialize(thisCell, thatCell, direction);
        passage = Instantiate(prefab) as MazePassage;
        if (passage is MazeDoor)
        {
            thatCell.Initialize(CreateRoom(thisCell.room.roomID));
        }
        else
        {
            thatCell.Initialize(thisCell.room);
        }
        passage.Initialize(thatCell, thisCell, direction.GetOposite());
    }
Beispiel #7
0
    private void CreatePassage(MazeCell parentCell, MazeCell neighbourCell, MazeDirection direction)
    {
        MazePassage prefab  = Random.value < doorProbability ? doorPrefab : passagePrefab;
        MazePassage passage = Instantiate(prefab);

        passage.Initialize(parentCell, neighbourCell, direction);
        passage = Instantiate(prefab);
        if (passage is MazeDoor)
        {
            neighbourCell.Initialize(CreateRoom(parentCell.room.settingsIndex));
        }
        else
        {
            neighbourCell.Initialize(parentCell.room);
        }
        passage.Initialize(neighbourCell, parentCell, direction.GetOpposite());
    }
Beispiel #8
0
    /// <summary>
    /// Creates the passage.
    /// Passage has a Initialize on either side.
    /// </summary>
    /// <param name="currentCell">Current cell.</param>
    /// <param name="neighbor">Neighbor.</param>
    /// <param name="direction">Direction.</param>
    void CreatePassage(MazeCell currentCell, MazeCell neighbor, MazeDirection direction)
    {
        MazePassage prefab  = Random.value < mDoorProbability ? mDoorPrefab : mPassgaePrefab;
        MazePassage passage = Instantiate(prefab) as MazePassage;

        passage.Initialize(currentCell, neighbor, direction);
        passage = Instantiate(prefab) as MazePassage;
        if (passage is MazeDoor)
        {
            neighbor.Initialized(CreateRoom(currentCell.mRoom.mSettingsIndex));
            mRoomCreatedTest += 1;
        }
        else
        {
            neighbor.Initialized(currentCell.mRoom);
        }
        passage.Initialize(neighbor, currentCell, direction.GetOpposite());
    }
Beispiel #9
0
    private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction)
    {
        //Debug.Log("CreatePassage " + cell.name + ", " + otherCell.name + ", " + direction.ToString());
        MazePassage prefab  = (Random.value < doorProbability) ? doorPrefab : passagePrefab; // 0.1 = 10%
        MazePassage passage = Instantiate <MazePassage>(prefab);

        passage.Initialize(cell, otherCell, direction);
        passage = Instantiate <MazePassage>(prefab);   // is 2nd needed? if yes then set pos.z = 0.475

        if (passage is MazeDoor)
        {
            otherCell.Initialize(CreateRoom(cell.room.settingsIndex));
        }
        else
        {
            otherCell.Initialize(cell.room);
        }

        passage.Initialize(otherCell, cell, direction.GetOpposite());
    }
Beispiel #10
0
    private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction)
    {
        bool createDoor = randomGenerator.NextDouble() < DoorProbability;

        if (createDoor)
        {
            MazePassage door = Instantiate(DoorPrefab) as MazePassage;
            door.Initialize(cell, otherCell, direction);
            MazePassage passage = Instantiate(PassagePrefab);
            passage.Initialize(otherCell, cell, direction.GetOpposite());
            otherCell.Initialize(CreateRoom(cell.Room.settingsIndex));
        }
        else
        {
            MazePassage passage = Instantiate(PassagePrefab) as MazePassage;
            passage.Initialize(cell, otherCell, direction);
            passage = Instantiate(PassagePrefab) as MazePassage;
            otherCell.Initialize(cell.Room);
            passage.Initialize(otherCell, cell, direction.GetOpposite());
        }
    }
Beispiel #11
0
    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());
    }
Beispiel #12
0
    private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction)
    {
        bool createDecor = Random.value < cell.room.settings.decorProbability ? true : false;

        if (otherCell.coordinates.x == playerCoordinates.x && otherCell.coordinates.z == playerCoordinates.z)
        {
            createDecor = false;
        }

        MazePassage prefab  = Random.value < doorProbability ? doorPrefab[Random.Range(0, doorPrefab.Length)] : passagePrefab;
        MazePassage passage = Instantiate(prefab, cell.transform.position, direction.ToRotation()) as MazePassage;

        passage.Initialize(cell, otherCell, direction);
        passage = Instantiate(prefab) as MazePassage;
        if (passage is MazeDoor)
        {
            otherCell.Initialize(CreateRoom(cell.room.settingsIndex), false, useShaderMaterials);
        }
        else
        {
            otherCell.Initialize(cell.room, createDecor, useShaderMaterials);
        }
        passage.Initialize(otherCell, cell, direction.GetOpposite());
    }
Beispiel #13
0
    /// <summary>
    /// Creates a passage between two cells, with no chance of a door.
    /// </summary>
    /// <param name="mazeCell">Current cell point.</param>
    /// <param name="otherMazeCell">Neighbour cell point.</param>
    /// <param name="direction">Direction of the passage.</param>
    private void CreatePassageInSameRoom(MazeCell mazeCell, MazeCell otherMazeCell, MazeDirection direction)
    {
        // Declare variables.
        MazePassage passage = Instantiate(_mazePassagePrefab);

        // Initializing.
        passage.Initialize(mazeCell, otherMazeCell, direction);
        passage = Instantiate(_mazePassagePrefab);
        passage.Initialize(otherMazeCell, mazeCell, direction.GetOpposite());

        // Then we have Maze check whether it's connecting different rooms, in which case it assimilates and removes the
        // other room.
        if (mazeCell.Room == otherMazeCell.Room)
        {
            return;
        }

        MazeRoom roomToAssimilate = otherMazeCell.Room;

        mazeCell.Room.Assimilate(roomToAssimilate);
        _rooms.Remove(roomToAssimilate);

        Destroy(roomToAssimilate);
    }
Beispiel #14
0
    // generate the puzzle rooms
    private void CreatePuzzleRoom()
    {
        // go through puzzle room candidates, different sized rooms can hold different puzzles
        // first cull small rooms from the list
        for (int r = 0; r < rooms.Count; r++)
        {
            if (rooms[r].getCells().Count > 30 && rooms[r].getCells().Count < 50)
            {
                puzzleRooms.Add(rooms[r]);
            }
        }
        // make sure there are only 3 puzzle rooms
        int num = puzzleRooms.Count;

        if (puzzleRooms.Count > 3)
        {
            for (int r = 0; r < num - 3; r++)
            {
                puzzleRooms.RemoveAt(puzzleRooms.Count - 1);
            }
        }
        // change the floor material for the rooms
        for (int r = 0; r < puzzleRooms.Count; r++)
        {
            puzzleRooms[r].roomSettings = roomSettings[roomSettings.Length - 1];
            for (int c = 0; c < puzzleRooms[r].getCells().Count; c++)
            {
                puzzleRooms[r].getCells()[c].updateMaterial(puzzleRooms[r]);
            }
        }
        // for each arch check if it connects a normal room with a puzzle room
        GameObject[] archList = GameObject.FindGameObjectsWithTag("ArchObject");
        for (int a = 0; a < archList.Length; a++)
        {
            // add a door
            MazeArch      arch = archList[a].GetComponent <MazeArch>();
            MazeCell      cellOne;
            MazeCell      cellTwo;
            MazeDirection dir;
            // if it does, then replace it with a door
            if (arch.cell.room.roomSettings.floorMaterial == roomSettings[roomSettings.Length - 1].floorMaterial)
            {
                if (PhotonNetwork.isMasterClient)
                {
                    cellOne = arch.cell;
                    cellTwo = arch.otherCell;
                    dir     = arch.direction;
                    //MazePassage prefabType = doorPrefab;
                    //MazePassage passage = Instantiate(prefabType) as MazePassage;
                    //passage.Initialize(cellOne, cellTwo, dir);

                    GameObject newDoor;
                    Vector3    doorPos = new Vector3(0, 0, 0);
                    Quaternion doorRot = new Quaternion(0f, 0f, 0f, 0f);
                    newDoor = (GameObject)PhotonNetwork.InstantiateSceneObject("Door", doorPos, doorRot, 0);
                    MazePassage passage = newDoor.GetComponent <MazePassage>();
                    passage.Initialize(cellOne, cellTwo, dir);
                }
            }
        }
    }
Beispiel #15
0
    // make two cells have passages towards each other
    private void CreatePassage(MazeCell firstCell, MazeCell secondCell, MazeDirection direction)
    {
        // use perlin noise to calculate where arches should be
        float       generatedNoise = Mathf.PerlinNoise((firstCell.coordinates.x * secondCell.coordinates.x) / (float)mazeGenerationNumber, (firstCell.coordinates.z * secondCell.coordinates.z) / (float)mazeGenerationNumber);
        MazePassage prefabType;

        if (generatedNoise < 0.2)
        {
            prefabType = archPrefab;
        }
        else
        {
            prefabType = passagePrefab;
        }

        // instantiate it once for each cell
        MazePassage passage = Instantiate(prefabType) as MazePassage;

        passage.Initialize(firstCell, secondCell, direction);
        passage = Instantiate(prefabType) as MazePassage;
        // create passage between two rooms
        if (passage is MazeArch)
        {
            secondCell.Initialize(CreateRoom(firstCell.room.settingsIndex));
        }
        else
        {
            secondCell.Initialize(firstCell.room);
        }
        passage.Initialize(secondCell, firstCell, direction.GetOpposite());

        /*GameObject newPassage;
         * Vector3 newPassagePos = new Vector3(0, 0, 0);
         * Quaternion newPassageRot = new Quaternion(0f, 0f, 0f, 0f);
         * if (generatedNoise < 0.2){
         *      newPassage = (GameObject) PhotonNetwork.Instantiate("Archway", newPassagePos, newPassageRot, 0);
         * }
         * else{
         *      newPassage = (GameObject) PhotonNetwork.Instantiate("MazePassage", newPassagePos, newPassageRot, 0);
         * }
         * MazePassage passage = newPassage.GetComponent<MazePassage>();
         * passage.Initialize(firstCell, secondCell, direction);
         *
         * if (generatedNoise < 0.2){
         *      newPassage = (GameObject) PhotonNetwork.Instantiate("Archway", newPassagePos, newPassageRot, 0);
         * }
         * else{
         *      newPassage = (GameObject) PhotonNetwork.Instantiate("MazePassage", newPassagePos, newPassageRot, 0);
         * }
         *
         * passage = newPassage.GetComponent<MazePassage>();
         * // create passage between two rooms
         * if (passage is MazeArch){
         *      secondCell.Initialize(CreateRoom(firstCell.room.settingsIndex));
         * }
         * else{
         *      secondCell.Initialize(firstCell.room);
         * }
         *
         * passage.Initialize(secondCell, firstCell, direction.GetOpposite());*/
    }
	private void DifferentRoomAction (MazeCell cell, MazeCell otherCell, MazePassage passage) {
		if (passage is MazeDoor)
			otherCell.Initialize (CreateRoom (cell.room.settingsIndex));
		else 
			otherCell.Initialize (cell.room);
	}
Beispiel #17
0
    //                                                                                          // 20cc : 23

    private void CreatePassageInSameRoom(MazeCell cell, MazeCell otherCell, MazeDirection direction)
    {
        MazePassage passage = Instantiate(passagePrefab) as MazePassage;

        passage.Initialize(cell, otherCell, direction);
    }
Beispiel #18
0
    private void CreatePassage(
        List <MazeCell> activeCells,
        MazeCell cell,
        MazeCell otherCell,
        MazeDirection direction)
    {                                       // Create one of the possible passable edges from one a cell in one
        // room to a cell in another.
        MazePassage prefab = passagePrefab; // generic passage

        if (cell.altitude == 0 &&
            Random.value < doorProbability)
        {
            // Possibly make a door from one room to the next
            prefab = doorPrefab;

            if (Random.value < doorProbability &&
                CanCreateStairs(cell, otherCell, direction))
            {
                // Instead of a door, let's try to make stairs. Stiars occupy
                // both cell and other cell and enforce constraints on
                // a low landing cell at the base of the stairs and a
                // high landing cell at the top of the stairs.
                prefab = passagePrefab;                 // Not a door after all!

                cell.accessory                         = Instantiate(stairsPrefab) as MazeCellAccessory;
                cell.accessory.cell                    = cell;
                cell.accessory.transform.parent        = cell.transform;
                cell.accessory.transform.localPosition = Vector3.zero;
                cell.accessory.transform.localRotation = direction.ToRotation();

                otherCell.Initialize(cell.GetRoomNumber());

                IntVector2 highLandingCoordinates = otherCell.coordinates +
                                                    direction.ToIntVector2();
                MazeCell highLandingCell = CreateCell(
                    highLandingCoordinates, 1, cellPrefab);
                activeCells.Add(highLandingCell);
                highLandingCell.Initialize(otherCell.GetRoomNumber() + 1);

                MazePassage landingPassage = Instantiate(prefab) as MazePassage;
                landingPassage.Initialize(otherCell, highLandingCell, direction);

                GameObject newColumn = Instantiate(columnPrefab) as GameObject;
                newColumn.transform.parent        = otherCell.transform;
                newColumn.transform.localPosition = Vector3.zero;
                newColumn.transform.localRotation = direction.ToRotation();

                if (null != railingColumnPrefab)
                {
                    GameObject newRailingColumn = Instantiate(railingColumnPrefab) as GameObject;
                    newRailingColumn.transform.parent        = highLandingCell.transform;
                    newRailingColumn.transform.localPosition = Vector3.zero;
                    newRailingColumn.transform.localRotation = direction.ToRotation();
                }
            }
            else
            {
                // Doors alsways change room numbers
                otherCell.Initialize(cell.GetRoomNumber() + 1);
            }
        }
        else
        {
            // This passage is neither door nor stair
            otherCell.Initialize(cell.GetRoomNumber());
            otherCell.altitude = cell.altitude;
            otherCell.transform.localPosition = new Vector3(otherCell.transform.localPosition.x,
                                                            otherCell.transform.localPosition.y + otherCell.altitude * 1.078f,
                                                            otherCell.transform.localPosition.z);
        }

        MazePassage passage = Instantiate(prefab) as MazePassage;

        passage.Initialize(cell, otherCell, direction);
    }