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.

53 lines
1.9 KiB

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