Esempio n. 1
0
 public void ReopenRoom()
 {
     for (int i = 0; i < 4; i++)
     {
         if (storedExits[i])
         {
             DisableWall(DirectionUtility.getDirection(i));
         }
     }
 }
Esempio n. 2
0
 public void CloseRoom()
 {
     for (int i = 0; i < 4; i++)
     {
         if (storedExits[i])
         {
             EnableWall(DirectionUtility.getDirection(i));
         }
     }
 }
Esempio n. 3
0
        public virtual void BuildTowards(Room target, Room _source, Room[,] floorLayout)
        {
            List <int> goingDirections = new List <int> {
                0, 1, 2, 3
            };

            foreach (int i in goingDirections)
            {
                int _x         = x + DirectionUtility.getX(i);
                int _y         = y + DirectionUtility.getY(i);
                int dist       = Mathf.Abs(x - target.x) + Mathf.Abs(y - target.y);
                int directDist = Mathf.Abs(_x - target.x) + Mathf.Abs(_y - target.y);

                if (directDist < dist && _x < floorLayout.GetLength(0) && _x >= 0 && _y < floorLayout.GetLength(1) && _y >= 0)
                {
                    //Build Towards that direction
                    if (floorLayout[_x, _y] == null)
                    {
                        Debug.Log("Tunneling " + x + ", " + y + " into " + _x + ", " + _y);
                        //If there is no room here, Tunnel!
                        RoomManager.instance.Tunnel(_x, _y, floorLayout, DirectionUtility.opposite(i), _source);
                        bool status = AddExit(DirectionUtility.getDirection(i), floorLayout);
                        if (status == true)
                        {
                            return;
                        }
                    }
                    else if (TestExit(i) == true)
                    {
                        Debug.Log("Building towards " + _x + ", " + _y);
                        floorLayout[_x, _y].BuildTowards(target, _source, floorLayout);
                        return;
                    }
                    else
                    {
                        //If there is a room there, connect them!
                        if (floorLayout[_x, _y].getBaseRoom() != _source)
                        {
                            floorLayout[_x, _y].Connect(_source);
                        }
                        RoomManager.instance.FuseRooms(this, floorLayout[_x, _y], floorLayout);
                        return;
                    }
                    //End
                    return;
                }
            }
            //If we've made it here, no direction is closer to the target, which means THIS IS THE TARGET!
            _source.Connect(target);
        }
Esempio n. 4
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);
    }