Exemplo n.º 1
0
    private async void ProcessInput(float delta)
    {
        _dir = new Vector3();
        Transform camXform = _camera.GlobalTransform;

        Vector2 inputMovementVector = new Vector2();

        if (Input.IsActionPressed("movement_forwards"))
        {
            inputMovementVector.y += 1; Walk();
        }
        if (Input.IsActionPressed("movement_backwards"))
        {
            inputMovementVector.y -= 1; Walk();
        }
        if (Input.IsActionPressed("movement_left"))
        {
            inputMovementVector.x -= 1; Walk();
        }
        if (Input.IsActionPressed("movement_right"))
        {
            inputMovementVector.x += 1; Walk();
        }

        if (canShoot)
        {
            if (Input.IsActionJustPressed("fire"))
            {
                _raycast.ForceRaycastUpdate();
                canShoot = false;
                pistolAnim.Play("player.shoot");
                gunAudio.PitchScale = (float)GD.RandRange(0.7, 1.3);
                gunAudio.Play();
                ammoBar.Call("Unload");
                if (_raycast.IsColliding())
                {
                    var body = _raycast.GetCollider();
                    if (body.HasMethod("Damage"))
                    {
                        body.Call("Damage");
                    }
                }
                ammoTimer.Start(0.2f);
                await ToSignal(ammoTimer, "timeout");

                ammoBar.Call("Reload");
                ammoTimer.Start(0.5f);
                await ToSignal(ammoTimer, "timeout");

                canShoot = true;
            }
        }


        if (Input.IsActionJustPressed("zoom"))
        {
            isZoomed = !isZoomed;
        }

        if (isZoomed)
        {
            _camera.Fov = Mathf.Lerp(_camera.Fov, zoomFov, delta * zoomSmooth);
        }
        else
        {
            _camera.Fov = Mathf.Lerp(_camera.Fov, normalFov, delta * zoomSmooth);
        }


        inputMovementVector = inputMovementVector.Normalized();

        _dir += -camXform.basis.z * inputMovementVector.y;
        _dir += camXform.basis.x * inputMovementVector.x;

        if (Input.IsActionJustPressed("ui_cancel"))
        {
            if (Input.GetMouseMode() == Input.MouseMode.Visible)
            {
                Input.SetMouseMode(Input.MouseMode.Captured);
            }
            else
            {
                Input.SetMouseMode(Input.MouseMode.Visible);
            }
        }
    }