Esempio n. 1
0
    private void FixedUpdate()
    {
        lr.SetPosition(0, rb.position);
        lr.SetPosition(1, connectingBody.position);
        dj.connectedBody = connectingBody;

        rb.rotation = 90.0f +
                      Mathf.Atan2(rb.position.y - connectingBody.position.y,
                                  rb.position.x - connectingBody.position.x) / Mathf.PI * 180;
        //Debug.Log(rb.rotation + " " + Mathf.Atan2(dj.reactionForce.y, dj.reactionForce.x) / Mathf.PI * 180 + " " + dj.reactionForce.y + " " + dj.reactionForce.x);
        //Debug.DrawRay(rb.position, dj.reactionForce);

        if (Mathf.Abs(rb.velocity.x) < 0.1f && Mathf.Abs(rb.velocity.y) < 0.1f)
        {
            CurrentPlayerPhase = TypePlayerPhase.middle;
        }
        else if (rb.position.x - connectingBody.position.x > 0 && rb.velocity.x > 0)
        {
            CurrentPlayerPhase = TypePlayerPhase.right1;
        }
        else if (rb.position.x - connectingBody.position.x > 0 && rb.velocity.x < 0)
        {
            CurrentPlayerPhase = TypePlayerPhase.right2;
        }
        else if (rb.position.x - connectingBody.position.x < 0 && rb.velocity.x > 0)
        {
            CurrentPlayerPhase = TypePlayerPhase.left2;
        }
        else if (rb.position.x - connectingBody.position.x < 0 && rb.velocity.x < 0)
        {
            CurrentPlayerPhase = TypePlayerPhase.left1;
        }
    }
    IEnumerator FinishEffectController()
    {
        finishEffect.position = rb.position;
        finishEffect.rotation = Quaternion.Euler(0.0f, 0.0f, Mathf.Atan2(rb.velocity.y, rb.velocity.x) * 180 / Mathf.PI + 90.0f);
        rb.rotation           = Mathf.Atan2(rb.velocity.y, rb.velocity.x) * 180 / Mathf.PI - 90;
        finishParticle.Play();
        rb.gravityScale    = 0;
        rb.velocity        = rb.velocity.normalized;
        CurrentPlayerPhase = TypePlayerPhase.finish;

        GameController.TapOnGameEvent    -= TapOnGameEvent;
        GameController.TapOffGameEvent   -= TapOffGameEvent;
        GameManager.ChangeNewMode        -= ChangeNewMode;
        GameController.CheckNearestEvent -= CheckNearestEvent;

        yield return(new WaitForSeconds(finishTime));

        rb.gravityScale = 1;
        finishParticle.Stop();
        rb.position = LevelStartPosition;
        rb.velocity = Vector2.zero;

        yield return(new WaitForFixedUpdate());

        rb.simulated = false;
        GameManager.Instance.Mode = GameMode.FinishMenu;
    }
    private void CheckNearestEvent()
    {
        float MaxDistance = 5.0f;

        if (rbNearestRope != null)
        {
            float dis = Vector2.Distance(rb.position, rbNearestRope.position);
            if (dis > MaxDistance)
            {
                NearestRope.Mode = RopeController.RopeMode.NotUsed;
                NearestRope      = null;
                rbNearestRope    = null;
            }
            else
            {
                MaxDistance = dis;
            }
        }

        if (GameController.DistanceToPoint != null)
        {
            foreach (GameController.DistanceToPointHandler element in GameController.DistanceToPoint.GetInvocationList())
            {
                float dis = element.Invoke(rb.position, out Rigidbody2D Element, out RopeController rope);

                if (MaxDistance > dis)
                {
                    if (NearestRope != null)
                    {
                        NearestRope.Mode = RopeController.RopeMode.NotUsed;
                    }
                    rbNearestRope    = Element;
                    NearestRope      = rope;
                    MaxDistance      = dis;
                    NearestRope.Mode = RopeController.RopeMode.Target;
                }
            }
        }

        CurrentPlayerPhase = TypePlayerPhase.ball;
    }
    IEnumerator LineRendererUpdate(Rigidbody2D rigidbody)
    {
        yield return(new WaitForFixedUpdate());

        dj.autoConfigureDistance = false;
        dj.distance -= distanceReduction;
        while (true)
        {
            rb.rotation = 90.0f + Mathf.Atan2(rb.position.y - rigidbody.position.y, rb.position.x - rigidbody.position.x) / Mathf.PI * 180;
            //Debug.Log(rb.rotation + " " + Mathf.Atan2(dj.reactionForce.y, dj.reactionForce.x) / Mathf.PI * 180 + " " + dj.reactionForce.y + " " + dj.reactionForce.x);
            //Debug.DrawRay(rb.position, dj.reactionForce);

            if (Mathf.Abs(rb.velocity.x) < 0.1f && Mathf.Abs(rb.velocity.y) < 0.1f)
            {
                CurrentPlayerPhase = TypePlayerPhase.middle;
            }
            else if (rb.position.x - rigidbody.position.x > 0 && rb.velocity.x > 0)
            {
                CurrentPlayerPhase = TypePlayerPhase.right1;
            }
            else if (rb.position.x - rigidbody.position.x > 0 && rb.velocity.x < 0)
            {
                CurrentPlayerPhase = TypePlayerPhase.right2;
            }
            else if (rb.position.x - rigidbody.position.x < 0 && rb.velocity.x > 0)
            {
                CurrentPlayerPhase = TypePlayerPhase.left2;
            }
            else if (rb.position.x - rigidbody.position.x < 0 && rb.velocity.x < 0)
            {
                CurrentPlayerPhase = TypePlayerPhase.left1;
            }

            lr.SetPosition(0, rb.position);
            lr.SetPosition(1, rigidbody.position);
            dj.connectedBody = rigidbody;

            yield return(new WaitForFixedUpdate());
        }
    }