|
@ -36,10 +36,11 @@ namespace Jumpy { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Update( |
|
|
public void Update( |
|
|
GameTime time, History<GamePadState> gamePad, List<Rectangle> collisionTargets) { |
|
|
|
|
|
|
|
|
GameTime time, History<GamePadState> gamePad, History<KeyboardState> keyboard, |
|
|
|
|
|
List<Rectangle> collisionTargets) { |
|
|
Point oldPosition = position; |
|
|
Point oldPosition = position; |
|
|
AirState oldAirState = airState; |
|
|
AirState oldAirState = airState; |
|
|
UpdateFromGamePad(time, gamePad); |
|
|
|
|
|
|
|
|
UpdateFromInput(time, gamePad, keyboard); |
|
|
|
|
|
|
|
|
Rectangle oldBbox = Bbox(oldPosition); |
|
|
Rectangle oldBbox = Bbox(oldPosition); |
|
|
Rectangle playerBbox = Bbox(position); |
|
|
Rectangle playerBbox = Bbox(position); |
|
@ -102,8 +103,10 @@ namespace Jumpy { |
|
|
// TODO: refactor input to have a virtual "which directions & buttons were being pressed"
|
|
|
// TODO: refactor input to have a virtual "which directions & buttons were being pressed"
|
|
|
// instead of complicated if-statements in this function.
|
|
|
// instead of complicated if-statements in this function.
|
|
|
// TODO: refactor to use a state-machine.
|
|
|
// TODO: refactor to use a state-machine.
|
|
|
void UpdateFromGamePad(GameTime time, History<GamePadState> gamePad) { |
|
|
|
|
|
if (gamePad[0].IsButtonDown(Buttons.A) && gamePad[1].IsButtonUp(Buttons.A) && |
|
|
|
|
|
|
|
|
void UpdateFromInput( |
|
|
|
|
|
GameTime time, History<GamePadState> gamePad, History<KeyboardState> 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) { |
|
|
airState == AirState.Ground) { |
|
|
pose = Pose.Jumping; |
|
|
pose = Pose.Jumping; |
|
|
airState = AirState.Jumping; |
|
|
airState = AirState.Jumping; |
|
@ -112,7 +115,8 @@ namespace Jumpy { |
|
|
return; |
|
|
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) { |
|
|
&& swordSwingTime <= 0) { |
|
|
pose = Pose.SwordSwing; |
|
|
pose = Pose.SwordSwing; |
|
|
swordSwingTime = 0.3; |
|
|
swordSwingTime = 0.3; |
|
@ -120,17 +124,23 @@ namespace Jumpy { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Vector2 leftStick = gamePad[0].ThumbSticks.Left; |
|
|
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; |
|
|
facing = Facing.Left; |
|
|
pose = Pose.Walking; |
|
|
pose = Pose.Walking; |
|
|
position.X -= (int) (moveSpeed * time.ElapsedGameTime.TotalSeconds); |
|
|
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; |
|
|
facing = Facing.Right; |
|
|
pose = Pose.Walking; |
|
|
pose = Pose.Walking; |
|
|
position.X += (int) (moveSpeed * time.ElapsedGameTime.TotalSeconds); |
|
|
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; |
|
|
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; |
|
|
pose = Pose.Stretching; |
|
|
} else { |
|
|
} else { |
|
|
pose = Pose.Standing; |
|
|
pose = Pose.Standing; |
|
|