Example #1
0
        public override void Update(double dt)
        {
            PrevKeyboard    = CurrentKeyboard;
            CurrentKeyboard = Keyboard.GetState();

            PrevMouse    = CurrentMouse;
            CurrentMouse = Mouse.GetState();

            bool isOverUI = IsOverUI();

            if (CurrentMouse.LeftButton == ButtonState.Pressed)
            {
                if (LeftButtonDown != null && !isOverUI)
                {
                    LeftButtonDown.Invoke(new InputEventArgs(this));
                }
            }

            if (CurrentMouse.RightButton == ButtonState.Pressed)
            {
                if (RightButtonDown != null && !isOverUI)
                {
                    RightButtonDown.Invoke(new InputEventArgs(this));
                }
            }

            if (CurrentMouse.LeftButton == ButtonState.Pressed && PrevMouse.LeftButton == ButtonState.Released)
            {
                if (LeftClick != null && !isOverUI)
                {
                    LeftClick.Invoke(new InputEventArgs(this));
                }
            }

            if (CurrentMouse.RightButton == ButtonState.Pressed && PrevMouse.RightButton == ButtonState.Released)
            {
                if (RightClick != null && !isOverUI)
                {
                    RightClick.Invoke(new InputEventArgs(this));
                }
            }

            foreach (KeyListener listener in _listeners)
            {
                if (CurrentKeyboard.IsKeyDown(listener.Primary) && (listener.Continuous || !PrevKeyboard.IsKeyDown(listener.Primary)))
                {
                    listener.Trigger(listener.Primary, this);
                }
                else if (CurrentKeyboard.IsKeyDown(listener.Alternate) && (listener.Continuous || !PrevKeyboard.IsKeyDown(listener.Alternate)))
                {
                    listener.Trigger(listener.Alternate, this);
                }
            }
        }
Example #2
0
 private void CheckJump()
 {
     if (!IsOnConveyor || IsWindingUp)
     {
         return;
     }
     if (CurrentKeyboard.IsKeyDown(Input.Jump) && PreviousKeyboard.IsKeyUp(Input.Jump) && AliveTimer > 0)
     {
         AnimationManager.Play(Animations["standing"]);
         AudioManager.PlayEffect(ContentManager.JumpSoundEffect);
         JumpLandingAnimation();
         IsJumping        = true;
         Speed            = Vector2.UnitY * JUMP_VELOCITY;
         FallAcceleration = 0;
         IsOnConveyor     = false;
     }
 }
Example #3
0
 public static bool IsKeyPressed(Keys key) => LastKeyboard.IsKeyUp(key) && CurrentKeyboard.IsKeyDown(key);
Example #4
0
        /// <summary>
        /// Updates the values in this <see cref="InputManager3D"/> by processing input states.
        /// </summary>
        /// <param name="dtSeconds">The amount of time since the last update, measured in seconds.</param>
        public void Update(float dtSeconds)
        {
            if (CurrentMouse != null)
            {
                if (CurrentMouse.IsButtonPressed(MouseButton.Left))
                {
                    CameraRotationY += (CurrentMouse.Position.X - lastMousePos.X) * MouseSensitivity;
                    CameraRotationX  = Math.Clamp(CameraRotationX + (CurrentMouse.Position.Y - lastMousePos.Y) * -MouseSensitivity, -1.57f, 1.57f);
                    if (LockMouseWhileRotating)
                    {
                        CurrentMouse.Position = lastMousePos;
                    }
                }

                lastMousePos = CurrentMouse.Position;
            }

            if (CurrentKeyboard != null)
            {
                float sinY = MathF.Sin(CameraRotationY);
                float cosY = MathF.Cos(CameraRotationY);

                if (CurrentKeyboard.IsKeyPressed(Key.W))
                {
                    CameraPosition += new Vector3(cosY, 0, sinY) * CameraMoveSpeed * dtSeconds;
                }
                if (CurrentKeyboard.IsKeyPressed(Key.S))
                {
                    CameraPosition -= new Vector3(cosY, 0, sinY) * CameraMoveSpeed * dtSeconds;
                }

                if (CurrentKeyboard.IsKeyPressed(Key.A))
                {
                    CameraPosition += new Vector3(sinY, 0, -cosY) * CameraMoveSpeed * dtSeconds;
                }
                if (CurrentKeyboard.IsKeyPressed(Key.D))
                {
                    CameraPosition -= new Vector3(sinY, 0, -cosY) * CameraMoveSpeed * dtSeconds;
                }

                if (CurrentKeyboard.IsKeyPressed(Key.E))
                {
                    CameraPosition.Y += CameraMoveSpeed * dtSeconds;
                }
                if (CurrentKeyboard.IsKeyPressed(Key.Q))
                {
                    CameraPosition.Y -= CameraMoveSpeed * dtSeconds;
                }
            }

            if (CurrentGamepad != null && CurrentGamepad.Thumbsticks.Count != 0)
            {
                Thumbstick thumbstick = CurrentGamepad.Thumbsticks[0];
                if (Math.Abs(thumbstick.Position) > 0.2f)
                {
                    CameraRotationY += thumbstick.X * dtSeconds * CameraThumbstickSensitivity;
                    CameraRotationX  = Math.Clamp(CameraRotationX - thumbstick.Y * dtSeconds * CameraThumbstickSensitivity, -1.57f, 1.57f);
                }

                if (CurrentGamepad.Thumbsticks.Count >= 2)
                {
                    thumbstick = CurrentGamepad.Thumbsticks[1];
                    if (Math.Abs(thumbstick.Position) > 0.2f)
                    {
                        float rot = thumbstick.Direction + CameraRotationY + MathF.PI / 2f;
                        float spd = thumbstick.Position * dtSeconds * CameraMoveSpeed;
                        CameraPosition.X += MathF.Cos(rot) * spd;
                        CameraPosition.Z += MathF.Sin(rot) * spd;
                    }
                }

                if (CurrentGamepad.Triggers.Count >= 2)
                {
                    if (CurrentGamepad.Triggers[0].Position > 0.2f)
                    {
                        CameraPosition.Y -= CurrentGamepad.Triggers[0].Position * dtSeconds * CameraMoveSpeed;
                    }
                    if (CurrentGamepad.Triggers[1].Position > 0.2f)
                    {
                        CameraPosition.Y += CurrentGamepad.Triggers[1].Position * dtSeconds * CameraMoveSpeed;
                    }
                }
            }
        }
Example #5
0
 bool Released(Keys key)
 {
     return(CurrentKeyboard.IsKeyUp(key) && LastKeyboard.IsKeyDown(key));
 }