Exemplo n.º 1
0
    // Update is called once per frame
    protected virtual void Update()
    {
        /* ON HIT */
        if (hit >= 0)
        {
            Color lerpedColor = Color.Lerp(Color.white, Color.red, Mathf.Sqrt(hit) / Mathf.Sqrt(25));
            render.color = lerpedColor;
            hit--;
        }

        /* ROTATION */
        // get position of main sprite and mouse
        Vector2 pos = rb.position;

        mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        // get directional vector and convert to angle
        direction = pos - mousePosition;
        angle     = Mathf.Atan2(direction.y, direction.x);



        /* ABILITIES */
        while (globalcd.isReady())
        {
            if (Input.GetKey("q"))
            {
                if (qcd.isReady())
                {
                    QAbility();
                    gcd();
                    qcd.setCd();
                }
                break;
            }
            else if (Input.GetKey("e"))
            {
                if (ecd.isReady())
                {
                    EAbility();
                    gcd();
                    ecd.setCd();
                }
                break;
            }
            else if (Input.GetKey(KeyCode.LeftShift))
            {
                if (lshiftcd.isReady())
                {
                    LShiftAbility(direction);
                    gcd();
                    lshiftcd.setCd();
                }
                break;
            }

            else if (Input.GetMouseButton(1))
            {
                if (rmbcd.isReady())
                {
                    RMBAbility();
                    gcd();
                    rmbcd.setCd();
                }
                break;
            }

            /* ARROW */
            else if (Input.GetMouseButton(0))
            {
                if (glcd.isReady())
                {
                    if (!clicked)
                    {
                        clicked = true;
                        LMBClicked();
                    }
                }
            }

            else if (clicked)
            {
                clicked = false;
                LMBReleased();
                gcd();
                glcd.setCd();
                break;
            }
            break;
        }

        /* HEALTH BAR */
        if (hbarupdatetime == 0)
        {
            healthbarback.transform.localScale = healthbar.transform.localScale;
            hbarupdatetime = 100;
        }
        else
        {
            hbarupdatetime--;
        }

        if (Vector2.Distance(prevPos, rb.position) > 0.1f || Vector2.Angle(prevRot, direction) > Vector2.Angle(new Vector2(1, 0.1f), Vector2.right))
        {
            snm.sendMessage("playerposition", "{ \"x\": " + rb.position.x.ToString() + " , \"y\": " + rb.position.y.ToString() + ", \"rx\": " + direction.normalized.x.ToString() + ", \"ry\": " + direction.normalized.y.ToString() + " }");
            prevPos = rb.position;
            prevRot = direction;
        }
    }
Exemplo n.º 2
0
 protected void gcd()
 {
     globalcd.setCd();
 }