예제 #1
0
    private Vector2 GetKeyboardMoveToPosition(InputEventKey _keyboardInput)
    {
        // Returns a vector2 position which the player will move based upon directions pressed on keyboard.
        // The keyboard input will return a simple direction which will be added to the players current grid position

        Vector2 moveToPosition = new Vector2();

        // Cardnial Directions
        if (_keyboardInput.IsAction("ui_up"))
        {
            moveToPosition = player.GridPosition + new Vector2(0, -1);
        }
        if (_keyboardInput.IsAction("ui_down"))
        {
            moveToPosition = player.GridPosition + new Vector2(0, 1);
        }
        if (_keyboardInput.IsAction("ui_right"))
        {
            moveToPosition = player.GridPosition + new Vector2(1, 0);
        }
        if (_keyboardInput.IsAction("ui_left"))
        {
            moveToPosition = player.GridPosition + new Vector2(-1, 0);
        }

        // Diagnial Directions
        if (_keyboardInput.IsActionPressed("ui_up") && _keyboardInput.IsActionPressed("ui_right"))
        {
            moveToPosition = player.GridPosition + new Vector2(1, -1);
        }
        if (_keyboardInput.IsActionPressed("ui_up") && _keyboardInput.IsActionPressed("ui_left"))
        {
            moveToPosition = player.GridPosition + new Vector2(-1, -1);
        }
        if (_keyboardInput.IsActionPressed("ui_down") && _keyboardInput.IsActionPressed("ui_right"))
        {
            moveToPosition = player.GridPosition + new Vector2(1, 1);
        }
        if (_keyboardInput.IsActionPressed("ui_left") && _keyboardInput.IsActionPressed("ui_right"))
        {
            moveToPosition = player.GridPosition + new Vector2(-1, 1);
        }

        return(moveToPosition);
    }
예제 #2
0
        public override void _Input(InputEvent @event)
        {
            if (@event is InputEventMouseMotion)
            {
                InputEventMouseMotion motion = (InputEventMouseMotion)@event;
                _head.RotateY(Mathf.Deg2Rad(-motion.Relative.x * _mouseSensitivity));
                float change = -motion.Relative.y * _mouseSensitivity;

                if ((change + _cameraAngle) < 90f && (change + _cameraAngle) > -90f)
                {
                    _view.RotateX(Mathf.Deg2Rad(change));
                    _cameraAngle += change;
                }
            }
            if (@event is InputEventKey)
            {
                InputEventKey key = (InputEventKey)@event;

                if (key.IsAction("ui_cancel"))
                {
                    Input.SetMouseMode(Input.MouseMode.Visible);
                }
            }
        }
예제 #3
0
    public override void _Input(InputEvent @event)
    {
        if (@event is InputEventKey)
        {
            //Downcast to key
            InputEventKey eventKey = (InputEventKey)@event;

            //Update Motion Input
            if (eventKey.IsAction("move_forward"))
            {
                SetMotionParameterAndConsumeInput(ref Vinput, false, eventKey, 0);
            }
            else if (eventKey.IsAction("move_backward"))
            {
                SetMotionParameterAndConsumeInput(ref Vinput, true, eventKey, 1);
            }
            else if (eventKey.IsAction("move_left"))
            {
                SetMotionParameterAndConsumeInput(ref Hinput, false, eventKey, 2);
            }
            else if (eventKey.IsAction("move_right"))
            {
                SetMotionParameterAndConsumeInput(ref Hinput, true, eventKey, 3);
            }
            else if (eventKey.IsAction("move_up"))
            {
                SetMotionParameterAndConsumeInput(ref Linput, true, eventKey, 4);
            }
            else if (eventKey.IsAction("move_down"))
            {
                SetMotionParameterAndConsumeInput(ref Linput, false, eventKey, 5);
            }

            if (eventKey.IsAction("release_mouse") && eventKey.Pressed)
            {
                Input.SetMouseMode(Input.GetMouseMode() == Input.MouseMode.Captured ? Input.MouseMode.Visible : Input.MouseMode.Captured);
            }
        }
        else if (@event is InputEventJoypadMotion)
        {
            //Downcast to motion
            InputEventJoypadMotion eventMotion = (InputEventJoypadMotion)@event;

            if (eventMotion.Axis == (int)JoystickList.Axis0 || eventMotion.Axis == (int)JoystickList.Axis1)
            {
                //Update Motion Input
                if (!Imobile)
                {
                    if (eventMotion.IsAction("move_forward"))
                    {
                        SetMotionParameterAndConsumeInput(ref Vinput, eventMotion);
                    }
                    else if (eventMotion.IsAction("move_backward"))
                    {
                        SetMotionParameterAndConsumeInput(ref Vinput, eventMotion);
                    }
                    else if (eventMotion.IsAction("move_left"))
                    {
                        SetMotionParameterAndConsumeInput(ref Hinput, eventMotion);
                    }
                    else if (eventMotion.IsAction("move_right"))
                    {
                        SetMotionParameterAndConsumeInput(ref Hinput, eventMotion);
                    }
                    else if (eventMotion.IsAction("move_up"))
                    {
                        SetMotionParameterAndConsumeInput(ref Linput, eventMotion);
                    }
                    else if (eventMotion.IsAction("move_down"))
                    {
                        SetMotionParameterAndConsumeInput(ref Linput, eventMotion);
                    }
                }
            }
            else if (eventMotion.Axis == (int)JoystickList.Axis2)
            {
                SetMotionParameterAndConsumeInput(ref Xinput, eventMotion);
            }
            else if (eventMotion.Axis == (int)JoystickList.Axis3)
            {
                SetMotionParameterAndConsumeInput(ref Yinput, eventMotion);
            }
        }
        else if (@event is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured)
        {
            //Downcast to mouse motion
            InputEventMouseMotion eventMouseMotion = (InputEventMouseMotion)@event;

            //Update camera angle
            MoveCamera(eventMouseMotion.Relative, SensitivityX, SensitivityY);

            //Apply rotation
            ApplyCameraAngle();

            //Tell event was handled
            GetTree().SetInputAsHandled();
        }
    }