Exemplo n.º 1
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Q))
     {
         //var t = Input.GetAccelerationEvent(0);
         Framework.FrameworkUtils.Application.Exit();
     }
     if (networkData.Count > 0)
     {
         var obj = networkData.Dequeue();
         ProtocolProcessor.MessagePump(obj);
     }
     sv.Update();
     if (Input.GetKeyDown(KeyCode.X))
     {
         target = true;
     }
     if (Input.GetKeyUp(KeyCode.X))
     {
         target = false;
     }
     if (Input.GetKeyDown(KeyCode.K))
     {
         sv.Negative = true;
     }
     if (Input.GetKeyUp(KeyCode.K))
     {
         sv.Negative = false;
     }
 }
Exemplo n.º 2
0
    private void Update()
    {
        // Quitting code would ordinarily be managed in a menu, but for this project, it's easier to put it here (since
        // there's one persistent copy of the player and the player is present in every scene).
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }

        if (inputLocked)
        {
            return;
        }

        justLaunched = false;

        Vector2 mousePosition  = Input.mousePosition;
        Vector2 playerPosition = transform.position;

        // The mouse overrides joystick aim if the mouse was moved this frame.
        if (mousePosition != previousMouseScreenPosition)
        {
            Vector2 worldPosition = Camera.main.ScreenToWorldPoint(mousePosition);

            previousMouseScreenPosition = mousePosition;
            launchVector = (worldPosition - playerPosition).normalized;
        }
        else
        {
            Vector2 joystickVector = new Vector2(Input.GetAxis("Joystick X"), -Input.GetAxis("Joystick Y"));

            if (joystickVector != Vector2.zero)
            {
                launchVector = joystickVector.normalized;
            }
        }

        if (charging)
        {
            elapsed += Time.deltaTime;
            elapsed  = Mathf.Min(elapsed, maximumChargeTime);

            float t = EaseFunctions.Ease(elapsed / maximumChargeTime, EaseTypes.QuadraticOut);

            chargeBar.Charge   = t;
            spring.targetValue = 1 - maximumSquishiness * t;

            if (Input.GetButtonUp("Launch") && launchVector != Vector2.zero)
            {
                Launch();
            }
        }
        else if (Input.GetButtonDown("Launch"))
        {
            elapsed  = 0;
            charging = true;
        }

        float launchRotation = Mathf.Atan2(launchVector.y, launchVector.x) * Mathf.Rad2Deg;

        Vector2 barPosition = playerPosition + launchVector * barOffset;

        Transform arrowTransform = chargeBar.transform;

        arrowTransform.position = new Vector3(barPosition.x, barPosition.y, BarZ);
        arrowTransform.rotation = Quaternion.Euler(0, 0, launchRotation);

        spring.Update();
        transform.localScale = new Vector3(spring.value, spring.value, 1);
    }