2020-01-18 03:41:45 +00:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Input;
|
|
|
|
|
|
|
|
namespace SemiColinGames {
|
|
|
|
struct Input {
|
2020-01-24 22:49:29 +00:00
|
|
|
public Vector2 Motion;
|
2020-01-18 03:41:45 +00:00
|
|
|
public bool Jump;
|
|
|
|
public bool Attack;
|
|
|
|
|
2020-01-24 22:49:29 +00:00
|
|
|
public bool Pause;
|
|
|
|
public bool Debug;
|
2020-01-18 03:41:45 +00:00
|
|
|
public bool Exit;
|
|
|
|
public bool FullScreen;
|
|
|
|
|
|
|
|
public Input(GamePadState gamePad, KeyboardState keyboard) {
|
|
|
|
// First we process normal buttons.
|
|
|
|
Jump = gamePad.IsButtonDown(Buttons.A) || gamePad.IsButtonDown(Buttons.B) ||
|
|
|
|
keyboard.IsKeyDown(Keys.J);
|
|
|
|
Attack = gamePad.IsButtonDown(Buttons.X) || gamePad.IsButtonDown(Buttons.Y) ||
|
|
|
|
keyboard.IsKeyDown(Keys.K);
|
|
|
|
|
|
|
|
// Then special debugging sorts of buttons.
|
2020-01-24 22:49:29 +00:00
|
|
|
Exit = keyboard.IsKeyDown(Keys.Escape) ||
|
|
|
|
(gamePad.IsButtonDown(Buttons.LeftShoulder) &&
|
|
|
|
gamePad.IsButtonDown(Buttons.RightShoulder) &&
|
|
|
|
gamePad.IsButtonDown(Buttons.Start));
|
|
|
|
FullScreen = keyboard.IsKeyDown(Keys.F12) || keyboard.IsKeyDown(Keys.OemPlus) ||
|
|
|
|
(gamePad.IsButtonDown(Buttons.LeftShoulder) &&
|
|
|
|
gamePad.IsButtonDown(Buttons.RightShoulder) &&
|
|
|
|
gamePad.IsButtonDown(Buttons.Back));
|
2020-01-18 03:41:45 +00:00
|
|
|
Debug = gamePad.IsButtonDown(Buttons.LeftShoulder) || keyboard.IsKeyDown(Keys.OemMinus);
|
2020-01-24 22:49:29 +00:00
|
|
|
Pause = gamePad.IsButtonDown(Buttons.Start) || keyboard.IsKeyDown(Keys.Pause);
|
2020-01-18 03:41:45 +00:00
|
|
|
|
|
|
|
// Then potential motion directions. If the player attempts to input opposite directions at
|
|
|
|
// once (up & down or left & right), those inputs cancel out, resulting in no motion.
|
|
|
|
Motion = new Vector2();
|
|
|
|
Vector2 leftStick = gamePad.ThumbSticks.Left;
|
|
|
|
bool left = leftStick.X < -0.5 || gamePad.IsButtonDown(Buttons.DPadLeft) ||
|
|
|
|
keyboard.IsKeyDown(Keys.A);
|
|
|
|
bool right = leftStick.X > 0.5 || gamePad.IsButtonDown(Buttons.DPadRight) ||
|
|
|
|
keyboard.IsKeyDown(Keys.D);
|
|
|
|
bool up = leftStick.Y > 0.5 || gamePad.IsButtonDown(Buttons.DPadUp) ||
|
|
|
|
keyboard.IsKeyDown(Keys.W);
|
|
|
|
bool down = leftStick.Y < -0.5 || gamePad.IsButtonDown(Buttons.DPadDown) ||
|
|
|
|
keyboard.IsKeyDown(Keys.S);
|
|
|
|
if (left && !right) {
|
|
|
|
Motion.X = -1;
|
|
|
|
}
|
|
|
|
if (right && !left) {
|
|
|
|
Motion.X = 1;
|
|
|
|
}
|
|
|
|
if (up && !down) {
|
|
|
|
Motion.Y = 1;
|
|
|
|
}
|
|
|
|
if (down && !up) {
|
|
|
|
Motion.Y = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|