Example #1
0
    // Sets a new current room, prepares adjacent room
    public void SetCurrentRoom(Room room)
    {
        currentRoom = room;

        // Do nothing if active
        if (room.GetState() == Room.RoomState.ACTIVE)
        {
        }
        // If prepared, show
        else if (room.GetState() == Room.RoomState.PREPARED)
        {
            room.ActivateRoom();
        }
        // If deactive, we need to prepare this room then show it
        else if (room.GetState() == Room.RoomState.DEACTIVE)
        {
            room.PrepareRoom();
            room.ActivateRoom();
        }

        // Set state to active
        room.SetState(Room.RoomState.ACTIVE);

        // Get new adjacent rooms and prepare them
        SetAdjacentRooms(room);
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        // lerpin'
        if (isTransitioning)
        {
            CamManager.Instance.mainCam.transform.position = new Vector3(Mathf.Lerp(previousCameraPosition.x, targetCameraPosition.x, lerpCamera),
                                                                         Mathf.Lerp(previousCameraPosition.y, targetCameraPosition.y, lerpCamera),
                                                                         CamManager.Instance.mainCam.transform.position.z);

            if (lerpCamera >= 1.0f)
            {
                previousRoom.DeactivateRoom();
                currentRoom.ActivateRoom();
                Debug.Log("Enabled ActivateRoom() Here");
                isTransitioning = false;
            }
            else
            {
                lerpCamera += lerpCameraSpeed;
            }
        }
        else
        {
            if (player != null && currentRoom != null)
            {
                Vector3 pos = player.transform.position;

                // if the player is out of the bounds of the room, clamp everything down.
                if (pos.x < currentRoom.roomCollider2D.bounds.min.x || pos.x > currentRoom.roomCollider2D.bounds.max.x ||
                    pos.y < currentRoom.roomCollider2D.bounds.min.y || pos.y > currentRoom.roomCollider2D.bounds.max.y)
                {
                    player.transform.position = new Vector3(Mathf.Clamp(pos.x, currentRoom.roomCollider2D.bounds.min.x, currentRoom.roomCollider2D.bounds.max.x),
                                                            Mathf.Clamp(pos.y, currentRoom.roomCollider2D.bounds.min.y, currentRoom.roomCollider2D.bounds.max.y),
                                                            pos.z);
                }
            }
        }
    }
Example #3
0
 public void Restart()     //called at player death in PlayerTakedamage
 {
     currentRoom  = startRoom;
     previousRoom = null;
     currentRoom.ActivateRoom();
 }