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 {
|
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);
|
Exit = keyboard.IsKeyDown(Keys.Escape) ||
|
||||||
FullScreen = gamePad.IsButtonDown(Buttons.Back) || keyboard.IsKeyDown(Keys.F12) ||
|
(gamePad.IsButtonDown(Buttons.LeftShoulder) &&
|
||||||
keyboard.IsKeyDown(Keys.OemPlus);
|
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.
|
||||||
|
@ -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();
|
if (!paused) {
|
||||||
player.Update(gameTime, input, collisionTargets);
|
List<Rectangle> collisionTargets = world.CollisionTargets();
|
||||||
|
player.Update(gameTime, input, collisionTargets);
|
||||||
camera.Update(player.Position);
|
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…
Reference in New Issue
Block a user