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); } } }
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; } }
public static bool IsKeyPressed(Keys key) => LastKeyboard.IsKeyUp(key) && CurrentKeyboard.IsKeyDown(key);
bool Pressed(Keys key) { return(CurrentKeyboard.IsKeyDown(key) && LastKeyboard.IsKeyUp(key)); }