Пример #1
0
 private void Awake()
 {
     if (instance != null)
     {
         Debug.LogWarning("More than one instance found");
         return;
     }
     instance = this;
 }
Пример #2
0
    public void Select(RoomBehaviour selectedRoom)
    {
        selectedBehaviour.gameObject.GetComponent <Outline> ().enabled = false;
        selectedBehaviour = selectedRoom;
        selectedBehaviour.gameObject.GetComponent <Outline> ().enabled = true;

        this.selectedDescription = selectedRoom.roomDescription;
        Debug.Log(selectedDescription.roomName + " isCrime? " + selectedDescription.isCrime);
        viewer.roomBehaviour = selectedRoom;
    }
Пример #3
0
    private RoomBehaviour getTarget()
    {
        RoomBehaviour target = roomList[Random.Range(0, roomList.Length)];

        while (target.state != RoomStates.OFF)
        {
            target = roomList[Random.Range(0, roomList.Length)];
        }
        return(target);
    }
Пример #4
0
    void Awake()
    {
        Time.timeScale = 1.0f;
        timeManager    = GetComponent <TimeManager> ();
        scoreManager   = GetComponent <ScoreManager> ();

        // init the roomList
        for (int i = 0; i < roomList.Length; i++)
        {
            roomList [i].defaultRoomDescription = selectedDescription;
            roomList [i].roomDescription        = selectedDescription;
        }
        selectedBehaviour = roomList [0];
        Select(selectedBehaviour);
    }
Пример #5
0
    public void BuildNavMesh()
    {
        if (m_NavMeshSurface != null)
        {
            m_NavMeshSurface.BuildNavMesh();
        }

        foreach (KeyValuePair <Vector2Int, RoomBehaviour> room in m_RoomsBehaviour)
        {
            RoomBehaviour roomBehaviour = room.Value;
            if (roomBehaviour != null)
            {
                roomBehaviour.FinishBaking();
            }
        }
    }
Пример #6
0
    void DrawMap()
    {
        SetRoomDoors();
        foreach (Room room in rooms)
        {
            if (room == null)
            {
                continue;                 //skip where there is no room
            }
            Vector2 drawPos = room.gridPos;
            drawPos.x *= 20;            //aspect ratio of map sprite
            drawPos.y *= 12;
            Vector2    mapPos = room.gridPos;
            GameObject obj;

            GameObject miniMap = Instantiate(miniMapCell, mapRoot);
            miniMap.transform.localPosition = mapPos;
            MiniMapCell mmC = miniMap.GetComponent <MiniMapCell>();

            if (room.type == 1)
            {
                obj = Instantiate(baseRoom, drawPos, Quaternion.identity);
                mmC.RoomEntered();
            }
            else if (room.type == -1)
            {
                obj = Instantiate(bossRoom, drawPos, Quaternion.identity);
                mmC.BossRoom();
            }
            else
            {
                obj = Instantiate(roomObj[Random.Range(0, roomObj.Count)], drawPos, Quaternion.identity);
            }



            RoomBehaviour rb = obj.GetComponent <RoomBehaviour>();
            rb.mapCell = mmC;
            rb.doorDown.closeNeighbour  = room.doorBot;
            rb.doorLeft.closeNeighbour  = room.doorLeft;
            rb.doorRight.closeNeighbour = room.doorRight;
            rb.doorUp.closeNeighbour    = room.doorTop;
        }
    }
Пример #7
0
    public void MoveRoom(RoomBehaviour src, Room dest, Vector2Int destPos)
    {
        Room room = src.room;

        for (int x = -1; x < 2; x++)
        {
            for (int y = -1; y < 2; y++)
            {
                var c = GetCell(room.X + x, room.Y + y);
                if (c != null && c.room == room)
                {
                    cells[room.X + x, room.Y + y] = null;
                }
            }
        }
        room.CopyFrom(dest);
        for (int x = -1; x < 2; x++)
        {
            for (int y = -1; y < 2; y++)
            {
                if (room.HasCell(x, y))
                {
                    cells[destPos.x + x, destPos.y + y] = room.GetCell(x, y);
                }
            }
        }
        src.transform.position = new Vector3(destPos.x, destPos.y, 0f);
        room.SetCoord(destPos.x, destPos.y);
        src.ApplyRotation();

        var conn = new List <Room>(room.connections);

        foreach (var n in conn)
        {
            n.connections.Remove(room);
            UpdateCellConnections(n);
        }
        room.connections.Clear();
        UpdateCellConnections(room);
    }
Пример #8
0
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;

        RoomBehaviour target = getTarget();

        if (lightsCount <= maxLights && timer > roomActivationDelay)
        {
            RoomDescription desc = GetRandomRoomDescription();
            target.ActivateState(minRoomActiveTime, maxRoomActiveTime, desc);
            timer = 0;
        }

        if (timeManager.IsTimeUp() && !guiCanvas.gameObject.activeInHierarchy)
        {
            Time.timeScale = 0f;
            guiCanvas.gameObject.SetActive(true);
            if (scoreManager.score > PlayerPrefs.GetInt("HighScore", 0))
            {
                PlayerPrefs.SetInt("HighScore", scoreManager.score);
            }
        }
    }
    private IEnumerator spawnRoomsCoroutine()
    {
        int roomLvlLower = RoomLevelLowerBound();
        int roomLvlUpper = RoomLevelUpperBound();

        int roomsToSpawns = NumberOfRoomsToSpawn();

        GameObject end = startPlatformEnd;

        for (int i = 0; i <= roomsToSpawns; i++)
        {
            yield return(null);

            int        roomLevel   = Random.Range(roomLvlLower, (roomLvlUpper + 1));
            GameObject roomToSpawn = RandomRoom(roomLevel);
            GameObject room        = SpawnRoom(roomToSpawn);

            RoomBehaviour roomBehaviour = room.GetComponent <RoomBehaviour>();
            Vector3       distance      = DistanceFromEndToStart(end, roomBehaviour.RoomStart);
            room.transform.position += distance;

            end = roomBehaviour.RoomEnd;
        }
    }
Пример #10
0
    private GameObject doRoom(GameObject room, int x, int y)
    {
        RoomProperties roomProperties = room.GetComponent <RoomProperties>();
        RoomBehaviour  roomBehaviour  = room.GetComponent <RoomBehaviour>();

        foreach (var exit in roomProperties.GetExitDirections())
        {
            if (exit.Value)
            {
                Dictionary <Direction, bool> directions = new Dictionary <Direction, bool>(); //change
                var currentX = x;
                var currentY = y;
                if (exit.Key == Direction.NORTH)
                {
                    currentY++;
                }
                else if (exit.Key == Direction.SOUTH)
                {
                    currentY--;
                }
                else if (exit.Key == Direction.EAST)
                {
                    currentX++;
                }
                else if (exit.Key == Direction.WEST)
                {
                    currentX--;
                }

                if (IsRoom(currentX, currentY))
                {
                    continue;
                }

                if (IsRoom(currentX - 1, currentY))
                {
                    if (HasExit(currentX - 1, currentY, Direction.EAST))
                    {
                        directions.Add(Direction.WEST, true);
                    }
                    else
                    {
                        directions.Add(Direction.WEST, false);
                    }
                }
                if (IsRoom(currentX + 1, currentY))
                {
                    if (HasExit(currentX + 1, currentY, Direction.WEST))
                    {
                        directions.Add(Direction.EAST, true);
                    }
                    else
                    {
                        directions.Add(Direction.EAST, false);
                    }
                }
                if (IsRoom(currentX, currentY - 1))
                {
                    if (HasExit(currentX, currentY - 1, Direction.NORTH))
                    {
                        directions.Add(Direction.SOUTH, true);
                    }
                    else
                    {
                        directions.Add(Direction.SOUTH, false);
                    }
                }
                if (IsRoom(currentX, currentY + 1))
                {
                    if (HasExit(currentX, currentY + 1, Direction.SOUTH))
                    {
                        directions.Add(Direction.NORTH, true);
                    }
                    else
                    {
                        directions.Add(Direction.NORTH, false);
                    }
                }
                var connectingRoom = FindRandomRoomWithExitAt(directions, currentX, currentY);
                todoRooms.Add(connectingRoom);
                AddRoom(connectingRoom, currentX, currentY);
            }
        }

        todoRooms.Remove(room);
        return(room);
    }
Пример #11
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);
                    }
                }
            }
        }
    }