|
|
@ -2,22 +2,27 @@ |
|
|
|
using Microsoft.Xna.Framework.Graphics; |
|
|
|
using Microsoft.Xna.Framework.Input; |
|
|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
namespace Jumpy { |
|
|
|
public class JumpyGame : Game { |
|
|
|
GraphicsDeviceManager graphics; |
|
|
|
|
|
|
|
// TODO: use a History<RenderTarget2D> but implement functions that let us re-use the
|
|
|
|
// RenderTargets instead of re-creating them every frame?
|
|
|
|
const int numRenderTargets = 1; |
|
|
|
RenderTarget2D[] renderTargets = new RenderTarget2D[numRenderTargets]; |
|
|
|
int renderTargetIdx = 0; |
|
|
|
|
|
|
|
SpriteBatch spriteBatch; |
|
|
|
SpriteFont font; |
|
|
|
KeyboardInput keyboardInput = new KeyboardInput(); |
|
|
|
bool fullScreen = false; |
|
|
|
IDisplay display; |
|
|
|
|
|
|
|
History<KeyboardState> keyboardHistory = new History<KeyboardState>(2); |
|
|
|
History<GamePadState> gamePadHistory = new History<GamePadState>(2); |
|
|
|
|
|
|
|
FpsCounter fpsCounter = new FpsCounter(); |
|
|
|
Player player; |
|
|
|
|
|
|
@ -56,21 +61,20 @@ namespace Jumpy { |
|
|
|
|
|
|
|
// Updates the game world.
|
|
|
|
protected override void Update(GameTime gameTime) { |
|
|
|
keyboardInput.Update(); |
|
|
|
GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); |
|
|
|
List<Keys> keysDown = keyboardInput.NewKeysDown(); |
|
|
|
gamePadHistory.Add(GamePad.GetState(PlayerIndex.One)); |
|
|
|
keyboardHistory.Add(Keyboard.GetState()); |
|
|
|
|
|
|
|
if (keysDown.Contains(Keys.F12)) { |
|
|
|
fullScreen = !fullScreen; |
|
|
|
display.SetFullScreen(fullScreen); |
|
|
|
if (gamePadHistory[0].Buttons.Start == ButtonState.Pressed || |
|
|
|
keyboardHistory[0].IsKeyDown(Keys.Escape)) { |
|
|
|
Exit(); |
|
|
|
} |
|
|
|
|
|
|
|
if (gamePadState.Buttons.Start == ButtonState.Pressed || |
|
|
|
keysDown.Contains(Keys.Escape)) { |
|
|
|
Exit(); |
|
|
|
if (keyboardHistory[0].IsKeyDown(Keys.F12) && keyboardHistory[1].IsKeyUp(Keys.F12)) { |
|
|
|
fullScreen = !fullScreen; |
|
|
|
display.SetFullScreen(fullScreen); |
|
|
|
} |
|
|
|
|
|
|
|
player.Update(gameTime, gamePadState); |
|
|
|
player.Update(gameTime, gamePadHistory); |
|
|
|
|
|
|
|
base.Update(gameTime); |
|
|
|
} |
|
|
|