Input: process debugging commands first & exit early if any are pressed.

GitOrigin-RevId: c36acce59305a0f2086b88c6206f73e3860e0c51
This commit is contained in:
Colin McMillen 2020-02-25 09:25:19 -05:00
parent 6802b3f162
commit 4e4c2cccb3

View File

@ -14,32 +14,38 @@ namespace SemiColinGames {
public bool FullScreen;
public Input(GamePadState gamePad, KeyboardState keyboard) {
// First we process normal buttons.
Motion = new Vector2();
// We check for debugging buttons first. If any are pressed, we suppress normal input;
// other button-presses correspond to special debugging things.
Exit = keyboard.IsKeyDown(Keys.Escape);
Restart = keyboard.IsKeyDown(Keys.F5);
FullScreen = keyboard.IsKeyDown(Keys.F12);
if (gamePad.IsButtonDown(Buttons.LeftShoulder) &&
gamePad.IsButtonDown(Buttons.RightShoulder)) {
Exit |= gamePad.IsButtonDown(Buttons.Start);
Restart |= gamePad.IsButtonDown(Buttons.Back);
FullScreen |= gamePad.IsButtonDown(Buttons.Y);
}
if (Exit || Restart || FullScreen) {
Jump = false;
Attack = false;
Pause = false;
Debug = false;
return;
}
// Then 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.
Exit = keyboard.IsKeyDown(Keys.Escape) ||
(gamePad.IsButtonDown(Buttons.LeftShoulder) &&
gamePad.IsButtonDown(Buttons.RightShoulder) &&
gamePad.IsButtonDown(Buttons.Start));
Restart = keyboard.IsKeyDown(Keys.F5) ||
(gamePad.IsButtonDown(Buttons.LeftShoulder) &&
gamePad.IsButtonDown(Buttons.RightShoulder) &&
gamePad.IsButtonDown(Buttons.Back));
FullScreen = keyboard.IsKeyDown(Keys.F12) || keyboard.IsKeyDown(Keys.OemPlus) ||
(gamePad.IsButtonDown(Buttons.LeftShoulder) &&
gamePad.IsButtonDown(Buttons.RightShoulder) &&
gamePad.IsButtonDown(Buttons.Y));
Debug = gamePad.IsButtonDown(Buttons.Back) || keyboard.IsKeyDown(Keys.OemMinus);
Pause = gamePad.IsButtonDown(Buttons.Start) || keyboard.IsKeyDown(Keys.Pause);
// 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);