Browse Source

add Pause functionality

GitOrigin-RevId: 18fb954757
master
Colin McMillen 4 years ago
parent
commit
83839c92ac
  1. 17
      Shared/Input.cs
  2. 18
      Shared/SneakGame.cs

17
Shared/Input.cs

@ -3,13 +3,14 @@ using Microsoft.Xna.Framework.Input;
namespace SemiColinGames { namespace SemiColinGames {
struct Input { struct Input {
public Vector2 Motion;
public bool Jump; public bool Jump;
public bool Attack; public bool Attack;
public Vector2 Motion;
public bool Pause;
public bool Debug;
public bool Exit; public bool Exit;
public bool FullScreen; public bool FullScreen;
public bool Debug;
public Input(GamePadState gamePad, KeyboardState keyboard) { public Input(GamePadState gamePad, KeyboardState keyboard) {
// First we process normal buttons. // First we process normal buttons.
@ -19,10 +20,16 @@ namespace SemiColinGames {
keyboard.IsKeyDown(Keys.K); keyboard.IsKeyDown(Keys.K);
// Then special debugging sorts of buttons. // Then special debugging sorts of buttons.
Exit = gamePad.IsButtonDown(Buttons.Start) || keyboard.IsKeyDown(Keys.Escape);
FullScreen = gamePad.IsButtonDown(Buttons.Back) || keyboard.IsKeyDown(Keys.F12) ||
keyboard.IsKeyDown(Keys.OemPlus);
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));
Debug = gamePad.IsButtonDown(Buttons.LeftShoulder) || keyboard.IsKeyDown(Keys.OemMinus); Debug = gamePad.IsButtonDown(Buttons.LeftShoulder) || 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 // 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. // once (up & down or left & right), those inputs cancel out, resulting in no motion.

18
Shared/SneakGame.cs

@ -13,6 +13,7 @@ namespace SemiColinGames {
SpriteBatch spriteBatch; SpriteBatch spriteBatch;
SpriteFont font; SpriteFont font;
bool fullScreen = false; bool fullScreen = false;
bool paused = false;
IDisplay display; IDisplay display;
History<Input> input = new History<Input>(2); History<Input> input = new History<Input>(2);
@ -71,6 +72,10 @@ namespace SemiColinGames {
Exit(); Exit();
} }
if (input[0].Pause && !input[1].Pause) {
paused = !paused;
}
if (input[0].FullScreen && !input[1].FullScreen) { if (input[0].FullScreen && !input[1].FullScreen) {
fullScreen = !fullScreen; fullScreen = !fullScreen;
display.SetFullScreen(fullScreen); display.SetFullScreen(fullScreen);
@ -80,10 +85,11 @@ namespace SemiColinGames {
Debug.Enabled = !Debug.Enabled; Debug.Enabled = !Debug.Enabled;
} }
List<Rectangle> collisionTargets = world.CollisionTargets();
player.Update(gameTime, input, collisionTargets);
camera.Update(player.Position);
if (!paused) {
List<Rectangle> collisionTargets = world.CollisionTargets();
player.Update(gameTime, input, collisionTargets);
camera.Update(player.Position);
}
base.Update(gameTime); base.Update(gameTime);
} }
@ -95,6 +101,10 @@ namespace SemiColinGames {
fpsCounter.Update(); fpsCounter.Update();
string fpsText = $"{GraphicsDevice.Viewport.Width}x{GraphicsDevice.Viewport.Height}, " + string fpsText = $"{GraphicsDevice.Viewport.Width}x{GraphicsDevice.Viewport.Height}, " +
$"{fpsCounter.Fps} FPS"; $"{fpsCounter.Fps} FPS";
if (paused) {
fpsText = fpsText + " (paused)";
}
Debug.SetFpsText(fpsText); Debug.SetFpsText(fpsText);
// Draw scene to RenderTarget. // Draw scene to RenderTarget.

Loading…
Cancel
Save