private void HandleMovement() { if (Keyboard.GetState().IsKeyDown(Keys.Right)) { RightPressed?.Invoke(this, null); } else if (Keyboard.GetState().IsKeyDown(Keys.Left)) { LeftPressed?.Invoke(this, null); } if (Keyboard.GetState().IsKeyDown(Keys.Up)) { UpPressed?.Invoke(this, null); } else if (Keyboard.GetState().IsKeyDown(Keys.Down)) { DownPressed?.Invoke(this, null); } if (Keyboard.GetState().IsKeyDown(Keys.PageUp)) { StrafeUpPressed?.Invoke(this, null); } else if (Keyboard.GetState().IsKeyDown(Keys.PageDown)) { StrafeDownPressed?.Invoke(this, null); } }
/// <summary> /// Waits for user's actions. /// </summary> public void Run() { while (true) { var keyPressed = Console.ReadKey(true); switch (keyPressed.Key) { case ConsoleKey.LeftArrow: LeftPressed?.Invoke(this, EventArgs.Empty); break; case ConsoleKey.RightArrow: RightPressed?.Invoke(this, EventArgs.Empty); break; case ConsoleKey.UpArrow: UpPressed?.Invoke(this, EventArgs.Empty); break; case ConsoleKey.DownArrow: DownPressed?.Invoke(this, EventArgs.Empty); break; } } }
private void HandleLook() { if (Mouse.GetState().RightButton == ButtonState.Released) { if (Mouse.GetState().Position.X > center.X) { RightPressed?.Invoke(this, null); } else if (Mouse.GetState().Position.X < center.X) { LeftPressed?.Invoke(this, null); } if (Mouse.GetState().Position.Y > center.Y) { UpPressed?.Invoke(this, null); } else if (Mouse.GetState().Position.Y < center.Y) { DownPressed?.Invoke(this, null); } } else { if (Mouse.GetState().Position.X > center.X) { RotateCWPressed?.Invoke(this, null); } else if (Mouse.GetState().Position.X < center.X) { RotateCCWPressed?.Invoke(this, null); } } }
public static void OnMovedLeft(float thumbstickX) { LeftPressed?.Invoke(null, new MoveInputEventArgs() { InputValue = thumbstickX }); }
void Update() { if (Input.GetKeyDown(_forwardKey)) { if (ForwardPressed != null) { ForwardPressed.Invoke( ); } } if (Input.GetKeyDown(_backwardKey)) { if (BackwardPressed != null) { BackwardPressed.Invoke( ); } } if (Input.GetKeyDown(_leftKey)) { if (LeftPressed != null) { LeftPressed.Invoke( ); } } if (Input.GetKeyDown(_rightKey)) { if (RightPressed != null) { RightPressed.Invoke( ); } } if (Input.GetKeyDown(_interactionKey)) { if (InteractionPressed != null) { InteractionPressed.Invoke( ); } } }
public void Start() { Task.Run(async() => { ISenseHat senseHat = await SenseHatFactory.GetSenseHat(); while (true) { if (senseHat.Joystick.Update()) { if (senseHat.Joystick.LeftKey == KeyState.Pressed) { LeftPressed?.Invoke(this, EventArgs.Empty); } else if (senseHat.Joystick.RightKey == KeyState.Pressed) { RightPressed?.Invoke(this, EventArgs.Empty); } else if (senseHat.Joystick.UpKey == KeyState.Pressed) { UpPressed?.Invoke(this, EventArgs.Empty); } else if (senseHat.Joystick.DownKey == KeyState.Pressed) { DownPressed?.Invoke(this, EventArgs.Empty); } else if (senseHat.Joystick.EnterKey == KeyState.Pressed) { EnterPressed?.Invoke(this, EventArgs.Empty); } } await Task.Delay(TimeSpan.FromMilliseconds(2)); } }); }
private void Left_OnPressed() { LeftPressed?.Invoke(); }