A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.3 KiB

  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Input;
  3. namespace SemiColinGames {
  4. struct Input {
  5. public Vector2 Motion;
  6. public bool Jump;
  7. public bool Attack;
  8. public bool Pause;
  9. public bool Debug;
  10. public bool Exit;
  11. public bool FullScreen;
  12. public Input(GamePadState gamePad, KeyboardState keyboard) {
  13. // First we process normal buttons.
  14. Jump = gamePad.IsButtonDown(Buttons.A) || gamePad.IsButtonDown(Buttons.B) ||
  15. keyboard.IsKeyDown(Keys.J);
  16. Attack = gamePad.IsButtonDown(Buttons.X) || gamePad.IsButtonDown(Buttons.Y) ||
  17. keyboard.IsKeyDown(Keys.K);
  18. // Then special debugging sorts of buttons.
  19. Exit = keyboard.IsKeyDown(Keys.Escape) ||
  20. (gamePad.IsButtonDown(Buttons.LeftShoulder) &&
  21. gamePad.IsButtonDown(Buttons.RightShoulder) &&
  22. gamePad.IsButtonDown(Buttons.Start));
  23. FullScreen = keyboard.IsKeyDown(Keys.F12) || keyboard.IsKeyDown(Keys.OemPlus) ||
  24. (gamePad.IsButtonDown(Buttons.LeftShoulder) &&
  25. gamePad.IsButtonDown(Buttons.RightShoulder) &&
  26. gamePad.IsButtonDown(Buttons.Back));
  27. Debug = gamePad.IsButtonDown(Buttons.LeftShoulder) || keyboard.IsKeyDown(Keys.OemMinus);
  28. Pause = gamePad.IsButtonDown(Buttons.Start) || keyboard.IsKeyDown(Keys.Pause);
  29. // Then potential motion directions. If the player attempts to input opposite directions at
  30. // once (up & down or left & right), those inputs cancel out, resulting in no motion.
  31. Motion = new Vector2();
  32. Vector2 leftStick = gamePad.ThumbSticks.Left;
  33. bool left = leftStick.X < -0.5 || gamePad.IsButtonDown(Buttons.DPadLeft) ||
  34. keyboard.IsKeyDown(Keys.A);
  35. bool right = leftStick.X > 0.5 || gamePad.IsButtonDown(Buttons.DPadRight) ||
  36. keyboard.IsKeyDown(Keys.D);
  37. bool up = leftStick.Y > 0.5 || gamePad.IsButtonDown(Buttons.DPadUp) ||
  38. keyboard.IsKeyDown(Keys.W);
  39. bool down = leftStick.Y < -0.5 || gamePad.IsButtonDown(Buttons.DPadDown) ||
  40. keyboard.IsKeyDown(Keys.S);
  41. if (left && !right) {
  42. Motion.X = -1;
  43. }
  44. if (right && !left) {
  45. Motion.X = 1;
  46. }
  47. if (up && !down) {
  48. Motion.Y = 1;
  49. }
  50. if (down && !up) {
  51. Motion.Y = -1;
  52. }
  53. }
  54. }
  55. }