diff --git a/Jumpy.Shared/JumpyGame.cs b/Jumpy.Shared/JumpyGame.cs index 333121d..bf86d88 100644 --- a/Jumpy.Shared/JumpyGame.cs +++ b/Jumpy.Shared/JumpyGame.cs @@ -20,8 +20,8 @@ namespace Jumpy { bool fullScreen = false; IDisplay display; - History keyboardHistory = new History(2); - History gamePadHistory = new History(2); + History keyboard = new History(2); + History gamePad = new History(2); FpsCounter fpsCounter = new FpsCounter(); Player player; @@ -61,20 +61,20 @@ namespace Jumpy { // Updates the game world. protected override void Update(GameTime gameTime) { - gamePadHistory.Add(GamePad.GetState(PlayerIndex.One)); - keyboardHistory.Add(Keyboard.GetState()); + gamePad.Add(GamePad.GetState(PlayerIndex.One)); + keyboard.Add(Keyboard.GetState()); - if (gamePadHistory[0].Buttons.Start == ButtonState.Pressed || - keyboardHistory[0].IsKeyDown(Keys.Escape)) { + if (keyboard[0].IsKeyDown(Keys.Escape) || gamePad[0].IsButtonDown(Buttons.Start)) { Exit(); } - if (keyboardHistory[0].IsKeyDown(Keys.F12) && keyboardHistory[1].IsKeyUp(Keys.F12)) { + if (keyboard[0].IsKeyDown(Keys.F12) && keyboard[1].IsKeyUp(Keys.F12) || + gamePad[0].IsButtonDown(Buttons.Back) && gamePad[1].IsButtonUp(Buttons.Back)) { fullScreen = !fullScreen; display.SetFullScreen(fullScreen); } - player.Update(gameTime, gamePadHistory); + player.Update(gameTime, gamePad); base.Update(gameTime); } diff --git a/Jumpy.Shared/Player.cs b/Jumpy.Shared/Player.cs index 55e7a4b..789dc82 100644 --- a/Jumpy.Shared/Player.cs +++ b/Jumpy.Shared/Player.cs @@ -29,9 +29,8 @@ namespace Jumpy { this.texture = texture; } - public void Update(GameTime time, History gamePadHistory) { - GamePadState gamePad = gamePadHistory[0]; - if (gamePad.Buttons.A == ButtonState.Pressed && airState == AirState.Ground) { + public void Update(GameTime time, History gamePad) { + if (gamePad[0].IsButtonDown(Buttons.A) && airState == AirState.Ground) { pose = Pose.Jumping; airState = AirState.Jumping; jumpTime = 0.5; @@ -39,23 +38,23 @@ namespace Jumpy { return; } // TODO: only swing the sword if button newly pressed (no turbosword) - if (gamePad.Buttons.X == ButtonState.Pressed && swordSwingTime <= 0) { + if (gamePad[0].IsButtonDown(Buttons.X) && swordSwingTime <= 0) { pose = Pose.SwordSwing; swordSwingTime = 0.3; return; } - Vector2 leftStick = gamePad.ThumbSticks.Left; - if (gamePad.DPad.Left == ButtonState.Pressed || leftStick.X < -0.5) { + Vector2 leftStick = gamePad[0].ThumbSticks.Left; + if (gamePad[0].IsButtonDown(Buttons.DPadLeft) || leftStick.X < -0.5) { facing = Facing.Left; pose = Pose.Walking; position.X -= (int) (moveSpeed * (float) time.ElapsedGameTime.TotalSeconds); - } else if (gamePad.DPad.Right == ButtonState.Pressed || leftStick.X > 0.5) { + } else if (gamePad[0].IsButtonDown(Buttons.DPadRight) || leftStick.X > 0.5) { facing = Facing.Right; pose = Pose.Walking; position.X += (int) (moveSpeed * (float) time.ElapsedGameTime.TotalSeconds); - } else if (gamePad.DPad.Down == ButtonState.Pressed || leftStick.Y < -0.5) { + } else if (gamePad[0].IsButtonDown(Buttons.DPadDown) || leftStick.Y < -0.5) { pose = Pose.Crouching; - } else if (gamePad.DPad.Up == ButtonState.Pressed || leftStick.Y > 0.5) { + } else if (gamePad[0].IsButtonDown(Buttons.DPadUp) || leftStick.Y > 0.5) { pose = Pose.Stretching; } else { pose = Pose.Standing;