/// <summary> /// Method, which processes keyboards events (key up and key down). /// </summary> /// <param name="source">Source of event. Not used.</param> /// <param name="args">Arguments of event. Uses to determine, is key up or down</param> public void KeyEventHandler(Object source, KeyboardKeyEventArgs args) { PlayerKeyEventArgs p_args = new PlayerKeyEventArgs(Keyboard.GetState().IsKeyUp(args.Key)); if (args.Key == keys.UpKey) OnUpCommand(p_args); if (args.Key == keys.DownKey) OnDownCommand(p_args); if (args.Key == keys.LeftKey) OnLeftCommand(p_args); if (args.Key == keys.RightKey) OnRightCommand(p_args); if (args.Key == keys.ShootKey) OnShootCommand(p_args); }
protected virtual void OnUpCommand(PlayerKeyEventArgs args) { if (UpCommand != null) UpCommand(this, args); }
protected virtual void OnShootCommand(PlayerKeyEventArgs args) { if (ShootCommand != null) ShootCommand(this, args); }
protected virtual void OnRightCommand(PlayerKeyEventArgs args) { if (RightCommand != null) RightCommand(this, args); }
protected virtual void OnLeftCommand(PlayerKeyEventArgs args) { if (LeftCommand != null) LeftCommand(this, args); }
protected virtual void OnDownCommand(PlayerKeyEventArgs args) { if (DownCommand != null) DownCommand(this, args); }
private void UpCommandHandler(Object source, PlayerKeyEventArgs args) { IsUpState = args.KeyReleased; }