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.

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