diff --git a/Jumpy.Shared/JumpyGame.cs b/Jumpy.Shared/JumpyGame.cs index 009eaa1..9b6124c 100644 --- a/Jumpy.Shared/JumpyGame.cs +++ b/Jumpy.Shared/JumpyGame.cs @@ -83,18 +83,19 @@ namespace Jumpy { } if (keyboard[0].IsKeyDown(Keys.F12) && keyboard[1].IsKeyUp(Keys.F12) || + keyboard[0].IsKeyDown(Keys.OemPlus) && keyboard[1].IsKeyUp(Keys.OemPlus) || gamePad[0].IsButtonDown(Buttons.Back) && gamePad[1].IsButtonUp(Buttons.Back)) { fullScreen = !fullScreen; display.SetFullScreen(fullScreen); } - if (gamePad[0].IsButtonDown(Buttons.LeftShoulder) && - gamePad[1].IsButtonUp(Buttons.LeftShoulder)) { + if (gamePad[0].IsButtonDown(Buttons.LeftShoulder) && gamePad[1].IsButtonUp(Buttons.LeftShoulder) || + keyboard[0].IsKeyDown(Keys.OemMinus) && keyboard[1].IsKeyUp(Keys.OemMinus)) { Debug.Enabled = !Debug.Enabled; } List collisionTargets = world.CollisionTargets(); - player.Update(gameTime, gamePad, collisionTargets); + player.Update(gameTime, gamePad, keyboard, collisionTargets); camera.Update(gameTime, player.Position); diff --git a/Jumpy.Shared/Player.cs b/Jumpy.Shared/Player.cs index 2f7e3ef..afa3975 100644 --- a/Jumpy.Shared/Player.cs +++ b/Jumpy.Shared/Player.cs @@ -36,10 +36,11 @@ namespace Jumpy { } public void Update( - GameTime time, History gamePad, List collisionTargets) { + GameTime time, History gamePad, History keyboard, + List collisionTargets) { Point oldPosition = position; AirState oldAirState = airState; - UpdateFromGamePad(time, gamePad); + UpdateFromInput(time, gamePad, keyboard); Rectangle oldBbox = Bbox(oldPosition); Rectangle playerBbox = Bbox(position); @@ -102,8 +103,10 @@ namespace Jumpy { // TODO: refactor input to have a virtual "which directions & buttons were being pressed" // instead of complicated if-statements in this function. // TODO: refactor to use a state-machine. - void UpdateFromGamePad(GameTime time, History gamePad) { - if (gamePad[0].IsButtonDown(Buttons.A) && gamePad[1].IsButtonUp(Buttons.A) && + void UpdateFromInput( + GameTime time, History gamePad, History keyboard) { + if ((gamePad[0].IsButtonDown(Buttons.A) && gamePad[1].IsButtonUp(Buttons.A) || + keyboard[0].IsKeyDown(Keys.J) && keyboard[1].IsKeyUp(Keys.J)) && airState == AirState.Ground) { pose = Pose.Jumping; airState = AirState.Jumping; @@ -112,7 +115,8 @@ namespace Jumpy { return; } - if (gamePad[0].IsButtonDown(Buttons.X) && gamePad[1].IsButtonUp(Buttons.X) + if ((gamePad[0].IsButtonDown(Buttons.X) && gamePad[1].IsButtonUp(Buttons.X) || + keyboard[0].IsKeyDown(Keys.K) && keyboard[1].IsKeyUp(Keys.K)) && swordSwingTime <= 0) { pose = Pose.SwordSwing; swordSwingTime = 0.3; @@ -120,17 +124,23 @@ namespace Jumpy { } Vector2 leftStick = gamePad[0].ThumbSticks.Left; - if (gamePad[0].IsButtonDown(Buttons.DPadLeft) || leftStick.X < -0.5) { + // TODO: have keyboard directions cancel each other out if mutually-incompatible keys are + // held down? + if (gamePad[0].IsButtonDown(Buttons.DPadLeft) || leftStick.X < -0.5 || + keyboard[0].IsKeyDown(Keys.A)) { facing = Facing.Left; pose = Pose.Walking; position.X -= (int) (moveSpeed * time.ElapsedGameTime.TotalSeconds); - } else if (gamePad[0].IsButtonDown(Buttons.DPadRight) || leftStick.X > 0.5) { + } else if (gamePad[0].IsButtonDown(Buttons.DPadRight) || leftStick.X > 0.5 || + keyboard[0].IsKeyDown(Keys.D)) { facing = Facing.Right; pose = Pose.Walking; position.X += (int) (moveSpeed * time.ElapsedGameTime.TotalSeconds); - } else if (gamePad[0].IsButtonDown(Buttons.DPadDown) || leftStick.Y < -0.5) { + } else if (gamePad[0].IsButtonDown(Buttons.DPadDown) || leftStick.Y < -0.5 || + keyboard[0].IsKeyDown(Keys.S)) { pose = Pose.Crouching; - } else if (gamePad[0].IsButtonDown(Buttons.DPadUp) || leftStick.Y > 0.5) { + } else if (gamePad[0].IsButtonDown(Buttons.DPadUp) || leftStick.Y > 0.5 || + keyboard[0].IsKeyDown(Keys.W)) { pose = Pose.Stretching; } else { pose = Pose.Standing;