Пример #1
0
    //get rooms with a certain number of 'openings'
    public List <Vector2Int> GetRoomsWithCertainOpeningNumber(int minNumber, int maxNumber)
    {
        List <Vector2Int> m_PossibleRooms = new List <Vector2Int>();

        foreach (KeyValuePair <Vector2Int, RoomOpeningTypes> pair in m_Taken)
        {
            Vector2Int       gridPos          = pair.Key;
            RoomOpeningTypes roomOpeningsType = pair.Value;

            //if grid pos already taken dont return, this is a hack, im so tired
            if (gridPos == m_SpawnRoomGridPos || gridPos == m_TradeRoomGridPos)
            {
                continue;
            }

            RoomOpeningInfo roomInfo = null;
            if (m_RoomOpeningsData.ContainsKey(roomOpeningsType))
            {
                roomInfo = m_RoomOpeningsData[roomOpeningsType];
            }

            if (roomInfo == null)
            {
                continue;
            }

            if (roomInfo.m_NumberOfOpenings >= minNumber && roomInfo.m_NumberOfOpenings <= maxNumber)
            {
                m_PossibleRooms.Add(gridPos);
            }
        }

        return(m_PossibleRooms);
    }
Пример #2
0
    public bool AddToTaken(Vector2Int pos, RoomOpeningTypes type)
    {
        if (m_Taken.ContainsKey(pos))
        {
            return(false);
        }

        m_Taken.Add(pos, type);
        return(true);
    }
Пример #3
0
    public void FixAllRooms()
    {
        foreach (KeyValuePair <Vector2Int, RoomOpeningTypes> roomInfo in m_Taken)
        {
            Vector2Int       gridPos  = roomInfo.Key;
            RoomOpeningTypes roomType = roomInfo.Value;

            //if for some reason theres no opening, check the surrounds and give it one
            if (roomType == RoomOpeningTypes.NO_OPENING)
            {
                roomType = ChangeCurrentRoomToExact(gridPos);
            }
        }
    }
Пример #4
0
    public void GenerateLevel()
    {
        m_Taken.Clear();
        m_RoomsBehaviour.Clear();
        foreach (Transform child in m_RoomParent.transform)
        {
            Destroy(child.gameObject);
        }

        Vector2Int start = Vector2Int.zero;

        m_SpawnRoomGridPos = m_BossRoomGridPos = m_TradeRoomGridPos = start;
        Queue <Vector2Int> m_RoomLocations = new Queue <Vector2Int>();

        m_Taken.Add(start, RoomOpeningTypes.L_R_U_D_OPENING);
        m_RoomLocations.Enqueue(start);

        while (m_RoomLocations.Count > 0)
        {
            Vector2Int       roomLocation = m_RoomLocations.Dequeue();
            RoomOpeningTypes roomType     = m_Taken[roomLocation];

            if (m_Taken.Count >= m_MinMaxRoomNumber.y)
            {
                //dont add anymore, edit current ones left in the queue instead
                if (m_Taken.ContainsKey(roomLocation))
                {
                    m_Taken[roomLocation] = ChangeCurrentRoomToExact(roomLocation);
                }
            }
            else
            {
                RoomOpeningInfo openingInfo = null;

                if (m_RoomOpeningsData.ContainsKey(roomType))
                {
                    openingInfo = m_RoomOpeningsData[roomType];
                }

                if (openingInfo == null)
                {
                    continue;
                }

                //make sure to check the door direction and have no rooms that is already taking that space
                Vector2Int newPos = roomLocation + new Vector2Int(0, 1);
                if (!m_Taken.ContainsKey(newPos) && openingInfo.m_UpOpening)
                {
                    if (AddToTaken(newPos, AddNextRoom(newPos)))
                    {
                        m_RoomLocations.Enqueue(newPos);
                    }
                }

                newPos = roomLocation + new Vector2Int(0, -1);
                if (!m_Taken.ContainsKey(newPos) && openingInfo.m_DownOpening)
                {
                    if (AddToTaken(newPos, AddNextRoom(newPos)))
                    {
                        m_RoomLocations.Enqueue(newPos);
                    }
                }

                newPos = roomLocation + new Vector2Int(1, 0);
                if (!m_Taken.ContainsKey(newPos) && openingInfo.m_RightOpening)
                {
                    if (AddToTaken(newPos, AddNextRoom(newPos)))
                    {
                        m_RoomLocations.Enqueue(newPos);
                    }
                }

                newPos = roomLocation + new Vector2Int(-1, 0);
                if (!m_Taken.ContainsKey(newPos) && openingInfo.m_LeftOpening)
                {
                    if (AddToTaken(newPos, AddNextRoom(newPos)))
                    {
                        m_RoomLocations.Enqueue(newPos);
                    }
                }
            }
        }

        FixAllRooms();      //make sure theres no weird rooms with broken paths
        DecideRoomType();   //set the room types
        InstantiateRooms(); //spawn and instantiate rooms
        InitRoomType();
        BuildNavMesh();
        SetAllRoomsInactive();
        InitUI(); //init the minimap stuff

        //setup initial start room
        if (m_RoomsBehaviour.ContainsKey(m_SpawnRoomGridPos))
        {
            m_RoomsBehaviour[m_SpawnRoomGridPos].gameObject.SetActive(true);
            m_RoomsBehaviour[m_SpawnRoomGridPos].SetupRoom();

            m_CurrRoom = m_PrevRoom = m_SpawnRoomGridPos;
        }
    }
Пример #5
0
    public void InstantiateRooms()
    {
        foreach (KeyValuePair <Vector2Int, RoomOpeningTypes> roomInfo in m_Taken)
        {
            Vector2Int       gridPos  = roomInfo.Key;
            RoomOpeningTypes roomType = roomInfo.Value;

            //if for some reason theres still no opening, check the surrounds and give it one
            if (roomType == RoomOpeningTypes.NO_OPENING)
            {
                roomType = ChangeCurrentRoomToExact(gridPos);
            }

            if (m_RoomObjectData.ContainsKey(roomType))
            {
                Vector2    worldPos = new Vector2(gridPos.x * m_RoomTileWidthHeight.x, gridPos.y * m_RoomTileWidthHeight.y);
                GameObject room     = null;
                if (gridPos == m_BossRoomGridPos)
                {
                    if (roomType == RoomOpeningTypes.L_OPENING)
                    {
                        room = Instantiate(m_SpecialRoomObjectData[RoomOpeningTypes.BOSS_ROOM_L_OPENING], worldPos, m_SpecialRoomObjectData[RoomOpeningTypes.BOSS_ROOM_L_OPENING].transform.rotation);
                    }
                    else if (roomType == RoomOpeningTypes.D_OPENING)
                    {
                        room = Instantiate(m_SpecialRoomObjectData[RoomOpeningTypes.BOSS_ROOM_D_OPENING], worldPos, m_SpecialRoomObjectData[RoomOpeningTypes.BOSS_ROOM_D_OPENING].transform.rotation);
                    }
                    else
                    {
                        room = Instantiate(m_SpecialRoomObjectData[RoomOpeningTypes.BOSS_ROOM_R_OPENING], worldPos, m_SpecialRoomObjectData[RoomOpeningTypes.BOSS_ROOM_R_OPENING].transform.rotation);
                    }
                }
                else if (gridPos == m_TradeRoomGridPos)
                {
                    if (m_SpecialRoomObjectData.ContainsKey(RoomOpeningTypes.TRADE_ROOM))
                    {
                        room = Instantiate(m_SpecialRoomObjectData[RoomOpeningTypes.TRADE_ROOM], worldPos, m_SpecialRoomObjectData[RoomOpeningTypes.TRADE_ROOM].transform.rotation);
                    }
                }
                else
                {
                    room = Instantiate(m_RoomObjectData[roomType], worldPos, m_RoomObjectData[roomType].transform.rotation);
                }

                if (m_RoomParent != null)
                {
                    room.transform.parent = m_RoomParent.transform;
                }

                RoomBehaviour roomBehaviour = room.GetComponent <RoomBehaviour>();
                if (roomBehaviour != null)
                {
                    roomBehaviour.SetRoomGridPos(gridPos);

                    if (!m_RoomsBehaviour.ContainsKey(gridPos))
                    {
                        m_RoomsBehaviour.Add(gridPos, roomBehaviour);
                    }
                }
            }
        }
    }