add Pause functionality
GitOrigin-RevId: 18fb95475734fef498e64d7d0d350135f652e05c
This commit is contained in:
parent
63aa190afe
commit
83839c92ac
@ -3,13 +3,14 @@ using Microsoft.Xna.Framework.Input;
|
||||
|
||||
namespace SemiColinGames {
|
||||
struct Input {
|
||||
public Vector2 Motion;
|
||||
public bool Jump;
|
||||
public bool Attack;
|
||||
public Vector2 Motion;
|
||||
|
||||
public bool Pause;
|
||||
public bool Debug;
|
||||
public bool Exit;
|
||||
public bool FullScreen;
|
||||
public bool Debug;
|
||||
|
||||
public Input(GamePadState gamePad, KeyboardState keyboard) {
|
||||
// First we process normal buttons.
|
||||
@ -19,10 +20,16 @@ namespace SemiColinGames {
|
||||
keyboard.IsKeyDown(Keys.K);
|
||||
|
||||
// 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);
|
||||
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.
|
||||
|
@ -13,6 +13,7 @@ namespace SemiColinGames {
|
||||
SpriteBatch spriteBatch;
|
||||
SpriteFont font;
|
||||
bool fullScreen = false;
|
||||
bool paused = false;
|
||||
IDisplay display;
|
||||
|
||||
History<Input> input = new History<Input>(2);
|
||||
@ -71,6 +72,10 @@ namespace SemiColinGames {
|
||||
Exit();
|
||||
}
|
||||
|
||||
if (input[0].Pause && !input[1].Pause) {
|
||||
paused = !paused;
|
||||
}
|
||||
|
||||
if (input[0].FullScreen && !input[1].FullScreen) {
|
||||
fullScreen = !fullScreen;
|
||||
display.SetFullScreen(fullScreen);
|
||||
@ -80,10 +85,11 @@ namespace SemiColinGames {
|
||||
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);
|
||||
}
|
||||
@ -95,6 +101,10 @@ namespace SemiColinGames {
|
||||
fpsCounter.Update();
|
||||
string fpsText = $"{GraphicsDevice.Viewport.Width}x{GraphicsDevice.Viewport.Height}, " +
|
||||
$"{fpsCounter.Fps} FPS";
|
||||
if (paused) {
|
||||
fpsText = fpsText + " (paused)";
|
||||
}
|
||||
|
||||
Debug.SetFpsText(fpsText);
|
||||
|
||||
// Draw scene to RenderTarget.
|
||||
|
Loading…
Reference in New Issue
Block a user