Exemplo n.º 1
0
    private void Start()
    {
        Camera camera    = GetComponent <Camera>();
        float  camWidth  = camera.orthographicSize * camera.aspect * 2;
        float  camHeight = camera.orthographicSize * 2;

        m_cameraPositionConstrains = new Vector2();
        // We are assuming, that camera is bigger than safe area
        m_cameraPositionConstrains.x = camWidth - m_cameraSafeArea.GetBounds().size.x;
        m_cameraPositionConstrains.y = camHeight - m_cameraSafeArea.GetBounds().size.y;
    }
Exemplo n.º 2
0
    private void Update()
    {
        Vector3 position = transform.position;
        //position = Vector3.SmoothDamp(position, m_objectToFollow.position, ref m_velocity, 0.1f);
        //position.z = transform.position.z;

        Bounds bounds = m_objectToFollowBounds.GetBounds();

        position.x = Mathf.Lerp(-m_bounds.x, m_bounds.x, (m_objectToFollow.position.x - bounds.min.x) / bounds.size.x);
        position.y = Mathf.Lerp(-m_bounds.y, m_bounds.y, (m_objectToFollow.position.y - bounds.min.y) / bounds.size.y);
        position.z = transform.position.z;

        transform.position = Vector3.SmoothDamp(transform.position, m_basePosition + position, ref m_velocity, 0.4f);
    }
Exemplo n.º 3
0
    private void Update()
    {
        Vector3 position = transform.position;

        Bounds objectToFollowBounds = m_objectToFollowBounds.GetBounds();
        Bounds cameraSafeAreaBounds = m_cameraSafeArea.GetBounds();

        float maxLeftCamPos   = -m_cameraPositionConstrains.x / 2 + cameraSafeAreaBounds.center.x;
        float maxRightCamPos  = m_cameraPositionConstrains.x / 2 + cameraSafeAreaBounds.center.x;
        float maxBottomCamPos = -m_cameraPositionConstrains.y / 2 + cameraSafeAreaBounds.center.y;
        float maxTopCamPos    = m_cameraPositionConstrains.y / 2 + cameraSafeAreaBounds.center.y;

        position.x = Mathf.Lerp(maxLeftCamPos, maxRightCamPos, Mathf.Clamp01((m_objectToFollow.position.x - objectToFollowBounds.min.x) / objectToFollowBounds.size.x));
        position.y = Mathf.Lerp(maxBottomCamPos, maxTopCamPos, Mathf.Clamp01((m_objectToFollow.position.y - objectToFollowBounds.min.y) / objectToFollowBounds.size.y));
        position.z = transform.position.z;

        transform.position = Vector3.SmoothDamp(transform.position, position, ref m_velocity, 0.4f);
    }
Exemplo n.º 4
0
    void Update()
    {
        Vector2 velocity = Velocity;

        if (IsOnWater && velocity.y > 0.0f)
        {
            Dude.SetBobyPartsKinematic(false);
            DudeAnimator.ClearClip();
            m_isPLayingSwimmAnim = false;
            IsOnWater            = false;
            IsInAir = true;

            m_waterWaver.Reset();

            if (m_waterCircles != null)
            {
                m_waterCircles.Stop();
                m_waterCircles = null;
            }
        }

        if (velocity.y > 0)
        {
            IsInAir = true;
        }

        Vector2 position = transform.position;
        float   waterHeight;
        int     waterStripIndex;
        Vector2 prevPosition = position;

        if (IsOnWater)
        {
            waterHeight = m_waterLevel.GetWaterHeight(transform.position.x, false);

            position           = transform.position;
            position.y         = waterHeight;
            position.y        += m_waterWaver.GetValue(Time.deltaTime);
            position.x        += velocity.x * Time.deltaTime;
            transform.position = position;
        }
        else
        {
            position += velocity * Time.deltaTime;
        }

        Bounds bounds = m_superheroArea.GetBounds();

        float bounce_power = 0.3f;

        if (position.x < bounds.min.x)
        {
            position.x = bounds.min.x;
            velocity.x = -velocity.x * bounce_power;
        }
        if (position.x > bounds.max.x)
        {
            position.x = bounds.max.x;
            velocity.x = -velocity.x * bounce_power;
        }
        if (position.y > bounds.max.y)
        {
            position.y = bounds.max.y;
            velocity.y = 0.0f;
        }

        if (m_rescueAreaLeft.IsPointInside(position) ||
            m_rescueAreaRight.IsPointInside(position))
        {
            NotifyCollisionWithRescueArea();
        }

        Bounds shoreLeftBounds = m_shoreLeftBounds.GetBounds();

        if (position.x < shoreLeftBounds.max.x && position.y < shoreLeftBounds.max.y && velocity.y < 0 && prevPosition.y >= shoreLeftBounds.max.y)
        {
            position.y = shoreLeftBounds.max.y;
            velocity   = Vector2.zero;
            if (IsInAir)
            {
                AudioManager.GetInstance().SoundLand.Play();
                IsInAir = false;
            }
        }
        else if (position.x < shoreLeftBounds.max.x && position.y < shoreLeftBounds.max.y && velocity.x < 0 && prevPosition.y <= shoreLeftBounds.max.y)
        {
            position.x = shoreLeftBounds.max.x;
            velocity.x = -velocity.x * bounce_power;
        }

        Bounds shoreRightBounds = m_shoreRightBounds.GetBounds();

        if (position.x > shoreRightBounds.min.x && position.y < shoreRightBounds.max.y && velocity.y < 0 && prevPosition.y >= shoreRightBounds.max.y)
        {
            position.y = shoreRightBounds.max.y;
            velocity   = Vector2.zero;
            if (IsInAir)
            {
                AudioManager.GetInstance().SoundLand.Play();
                IsInAir = false;
            }
        }
        else if (position.x > shoreRightBounds.min.x && position.y < shoreRightBounds.max.y && velocity.x > 0 && prevPosition.y <= shoreRightBounds.max.y)
        {
            position.x = shoreRightBounds.min.x;
            velocity.x = -velocity.x * bounce_power;
        }

        waterHeight = m_waterLevel.GetWaterHeight(transform.position.x, false);

        if (position.y <= waterHeight && !IsOnWater && velocity.y <= 0.0f)
        {
            IsOnWater = true;
            IsInAir   = false;

            SpawWaterCircles(position);
            // TODO, water circles
            // m_water.Impulse(waterStripIndex, Mathf.Min(3.0f, Velocity.magnitude), position.x);
            velocity.y = 0.0f;
            velocity.x = 0.0f;

            WaterSplash splash = WaterSplashPool.Instance.Get();
            if (splash != null)
            {
                splash.Splash(1.0f, Vector2.up, waterHeight, position.x);
            }
            AudioManager.GetInstance().SoundWaterSplash.Play();
        }

        if (IsOnWater && velocity.x != 0.0f)
        {
            if (!AudioManager.GetInstance().SoundSwim.IsPlaying())
            {
                AudioManager.GetInstance().SoundSwim.Play();
            }

            m_nextWaterCircleWhenSwimming -= Time.deltaTime;
            if (m_nextWaterCircleWhenSwimming <= 0.0f)
            {
                m_nextWaterCircleWhenSwimming = Random.Range(0.2f, 0.4f);
                SpawWaterCircles(position);
            }
        }
        else
        {
            if (AudioManager.GetInstance().SoundSwim.IsPlaying())
            {
                AudioManager.GetInstance().SoundSwim.Stop();
            }
        }

        if (IsOnWater && !m_isPLayingSwimmAnim)
        {
            Dude.SetBobyPartsKinematic(true);
            if (Dude.IsConnected(BodyPartType.HandLeft))
            {
                Dude.SetBobyPartKinematic(BodyPartType.HandLeft, false);
            }
            if (Dude.IsConnected(BodyPartType.HandRight))
            {
                Dude.SetBobyPartKinematic(BodyPartType.HandRight, false);
            }
            DudeAnimator.Swim();
            m_isPLayingSwimmAnim = true;
            m_isPLayingJumpAnim  = false;
        }

        if (!IsOnWater && !m_isPLayingJumpAnim)
        {
            Dude.SetBobyPartsKinematic(true);
            if (Dude.IsConnected(BodyPartType.HandLeft))
            {
                Dude.SetBobyPartKinematic(BodyPartType.HandLeft, false);
            }
            if (Dude.IsConnected(BodyPartType.HandRight))
            {
                Dude.SetBobyPartKinematic(BodyPartType.HandRight, false);
            }
            DudeAnimator.Jump();
            m_isPLayingJumpAnim = true;
        }

        Velocity           = velocity;
        transform.position = new Vector3(position.x, position.y, -0.3f);
    }