Beispiel #1
0
 public Floor(int _xSize, int _ySize, List <SpecialRoom> _room, SpecialRoom _entrance)
 {
     xSize    = _xSize;
     ySize    = _ySize;
     room     = _room;
     Entrance = _entrance;
 }
Beispiel #2
0
    public void createFloor(Floor thisFloor)
    {
        //Get RoomTemplate that is part of the MazeGenerator Object
        //roomList = GameObject.FindWithTag("Rooms").GetComponent<RoomTemplate>();
        roomList = gameObject.GetComponent <RoomTemplate>();
        //roomList = this.gameObject.GetComponent<RoomTemplate>();
        if (!roomList)
        {
            Debug.LogException(new Exception("Could not find RoomTemplate object!"));
        }

        //Get the full list of rooms from floor class
        mainRooms = thisFloor.GetRooms();
        mainRooms.Add(thisFloor.GetEntrance());
        List <SpecialRoom> createdMainRooms = new List <SpecialRoom>();

        //Declare for layout of this floor
        Room[,] floorLayout = new Room[thisFloor.xSize, thisFloor.ySize];

        //Place each importantRoom in a random place on the floor
        foreach (SpecialRoom _room in mainRooms)
        {
            bool repeat = false;
            do
            {
                _room.x = (int)Random.Range(0, thisFloor.xSize - 1);
                _room.y = (int)Random.Range(0, thisFloor.ySize - 1);
                repeat  = CheckSpot(_room.x, _room.y, floorLayout);
                if (repeat == false)
                {
                    //After going through exits, create this mainRoom
                    SpecialRoom tempScript = Instantiate(_room.gameObject, new Vector3(_room.x * ROOM_SIZE_X, _room.y * -ROOM_SIZE_Y, 0), Quaternion.identity).GetComponent <SpecialRoom>();
                    floorLayout[_room.x, _room.y] = tempScript;
                    if (tempScript)
                    {
                        tempScript.Initialize();
                        createdMainRooms.Add(tempScript);
                    }
                }
            } while(repeat);
        }

        //Create Connections
        //Go through each reqired room that was placed and build a graph to connect them all to each other
        foreach (SpecialRoom _room in createdMainRooms)
        {
            //Debug.Log("Connecting room " + _room.gameObject.name);
            bool[] exits = FindDirections(_room.x, _room.y, floorLayout, _room.getExits());
            //Go through each exit
            for (int i = 0; i < 4; i++)
            {
                //Debug.Log("Direction " + i);
                //yield return 0;
                //_room.setExit(i, exits[i]);
                if (exits[i])
                {
                    //Check if a room has somehow been created in the interim
                    if (floorLayout[_room.x + DirectionUtility.getX(i), _room.y + DirectionUtility.getY(i)] == null)
                    {
                        //Call recursive algorithm that begins making corridor rooms starting from each exit
                        Tunnel(_room.x + DirectionUtility.getX(i), _room.y + DirectionUtility.getY(i), floorLayout, DirectionUtility.opposite(i), _room);
                        //Make this mainRoom open or close walls depending on which exits have been set to open
                        _room.DisableWall(DirectionUtility.getDirection(i));
                        //Debug.Log("Cleanedup");
                        //yield return 0;
                    }/* else {
                      * //Check if the wall doesn't open to this room
                      * bool[] roomExits = floorLayout[_room.x + DirectionUtility.getX(i), _room.y + DirectionUtility.getY(i)].getExits();
                      * if(roomExits[DirectionUtility.getIndex(DirectionUtility.opposite(i))] == false) {
                      * //If the room doesn't open up, block it off
                      * _room.EnableWall(DirectionUtility.getDirection(i));
                      * }
                      * }*/
                }
            }
        }

        //Go through all SpecialRooms and check if any are not connected
        foreach (SpecialRoom _room in createdMainRooms)
        {
            for (int attempt = 0; attempt < 3; attempt++)
            {
                if (_room.isConnected() == false)
                {
                    // Force a connection by calling tunnel on an outskirt room
                    //Build towards a random room
                    SpecialRoom targetRoom = null;
                    for (int index = 0; index < createdMainRooms.Count && targetRoom == _room; index++)
                    {
                        targetRoom = createdMainRooms[index];
                    }
                    _room.BuildTowards(targetRoom, _room, floorLayout);
                }
            }
        }

        Player.GetPlayer().
        SetPosition((Vector2)(GameObject.FindWithTag("SpawnPoint").transform.position), 0);
    }
Beispiel #3
0
    public static bool[] FindDirections(int x, int y, Room[,] floorLayout, Room _baseRoom)
    {
        bool[]     exits           = new bool[4];
        List <int> goingDirections = new List <int> {
            0, 1, 2, 3
        };

        do
        {
            foreach (int i in goingDirections)
            {
                //Make sure we're inside the bounds of the loop
                int _x = x + DirectionUtility.getX(i);
                int _y = y + DirectionUtility.getY(i);
                if (_x < floorLayout.GetLength(0) && _x >= 0 && _y < floorLayout.GetLength(1) && _y >= 0)
                {
                    if (floorLayout[_x, _y] == null)
                    {
                        //Randomize whether this exit will be used
                        if (Random.Range(0, 100) < ROOM_CHANCE)
                        {
                            exits[i] = true;
                        }
                    }
                    else
                    {
                        //Check if this this room is connected to an UNCONNECTED MAINROOM
                        if ((floorLayout[_x, _y].isConnected() == false || _baseRoom.isConnected() == false) && floorLayout[_x, _y].getBaseRoom() != _baseRoom)
                        {
                            //Open this entrance of the mainRoom
                            //_checkedRoom.DisableWall(DirectionUtility.opposite(i));
                            bool addStatus = floorLayout[_x, _y].AddExit(DirectionUtility.opposite(i), floorLayout);
                            if (addStatus == true)
                            {
                                //Flag connection
                                _baseRoom.Connect(floorLayout[_x, _y]);
                                exits[i] = true;
                            }
                        }
                        //Make sure we're not dealing with a special room (that only opens up IF we're not connected, so get with the program!)
                        SpecialRoom tempRoom = floorLayout[_x, _y] as SpecialRoom;
                        if (tempRoom == null)
                        {
                            //Check if room this one is facing is already open to this room
                            bool[] roomExits = floorLayout[_x, _y].getExits();
                            if (roomExits[DirectionUtility.getIndex(DirectionUtility.opposite(i))] == true)
                            {
                                exits[i] = true;
                            }
                        }

                        /*
                         * foreach(SpecialRoom _checkedRoom in mainRooms) {
                         * if(floorLayout[_x,_y]==((Room) _checkedRoom) && ((Room) _checkedRoom) != _baseRoom) {
                         *  //If it is, check if this mainRoom is connected to another room yet
                         *  //if((!_checkedRoom.isConnected() || !_baseRoom.isConnected()) && roomExits[DirectionUtility.getIndex(DirectionUtility.opposite(i))] == true) {
                         *  if(!_checkedRoom.isConnected() || !_baseRoom.isConnected() || roomExits[DirectionUtility.getIndex(DirectionUtility.opposite(i))] == true) {
                         *    //If it isn't, connect it
                         *    _baseRoom.Connect(_checkedRoom);
                         *    exits[i] = true;
                         *    noExit = false;
                         *    //Open this entrance of the mainRoom
                         *    _checkedRoom.DisableWall(DirectionUtility.opposite(i));
                         *  }
                         * }
                         * }*/
                    }
                }
                //Now that everything has been checked, remove this direction
                goingDirections.Remove(i);
                break;
            } // End of for loop
        } while(goingDirections.Count > 0);

        return(exits);
    }
 public FakeAdresseable(StageRoom _stage, SpecialRoom _special, GameObject _prefab)
 {
     stage       = _stage;
     special     = _special;
     scenePrefab = _prefab;
 }
        private static void CalculateSpecialRoom()
        {
            if (TerrainNumber % 3 == 0)
            {
                _currentSpecial = SpecialRoom.SrNormal;
                _shop = true;
            }
            else
            {
                _currentSpecial = SpecialRoom.SrNormal;
                _shop = false;
                if (TerrainNumber < SpecialRoomStart)
                {
                    _currentSpecial = SpecialRoom.SrNormal;
                }
                else
                {
                    if (CalculatePercent(_specialRoomPercent))
                    {
                        int random = Helper.Random.Next(0, 7);

                        if (random == 0)
                        {
                            _currentSpecial = SpecialRoom.SrEvileye;
                            _evilEyeNumber *= 4;
                            _evilEyeSentryNumber *= 3;
                        }

                        if (random == 1)
                            {
                            _currentSpecial = SpecialRoom.SrRoachqueen;
                            }

                        if (random == 2)
                            {
                            _currentSpecial = SpecialRoom.SrGelbaby;
                                _gelBabyNumber *= 5;
                            }

                        if (random == 3)
                            {
                            _currentSpecial = SpecialRoom.SrTrapdoor;
                                _wraithwingNumber *= 3;
                            }

                        if (random == 4)
                            {
                            _currentSpecial = SpecialRoom.SrOrthosquare;
                            }

                        if (random == 5)
                            {
                            _currentSpecial = SpecialRoom.SrBrokenwall;
                            }

                        if (random == 6)
                            {
                            _currentSpecial = SpecialRoom.SrZombie;
                                _zombieNumber *= 4;
                            }
                    }
                    else
                    {
                        _currentSpecial = SpecialRoom.SrNormal;
                    }
                }
            }
        }
 public static void ResetValues()
 {
     Difficulty = 325;
     TerrainNumber = 1;
     _currentSpecial = SpecialRoom.SrNormal;
 }
 public void CloseDoors(SpecialRoom room)
 {
     room.CloseRoom();
     Timing.RunCoroutine(GameManager.CameraShake(2).CancelWith(Camera.main.gameObject));
 }