add keyboard controls for Player & toggling debug info
GitOrigin-RevId: 0ab5e524855b29d8a6261aef328a91893b2b4897
This commit is contained in:
parent
7ed88960a5
commit
37e3a8baba
@ -83,18 +83,19 @@ namespace Jumpy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (keyboard[0].IsKeyDown(Keys.F12) && keyboard[1].IsKeyUp(Keys.F12) ||
|
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)) {
|
gamePad[0].IsButtonDown(Buttons.Back) && gamePad[1].IsButtonUp(Buttons.Back)) {
|
||||||
fullScreen = !fullScreen;
|
fullScreen = !fullScreen;
|
||||||
display.SetFullScreen(fullScreen);
|
display.SetFullScreen(fullScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gamePad[0].IsButtonDown(Buttons.LeftShoulder) &&
|
if (gamePad[0].IsButtonDown(Buttons.LeftShoulder) && gamePad[1].IsButtonUp(Buttons.LeftShoulder) ||
|
||||||
gamePad[1].IsButtonUp(Buttons.LeftShoulder)) {
|
keyboard[0].IsKeyDown(Keys.OemMinus) && keyboard[1].IsKeyUp(Keys.OemMinus)) {
|
||||||
Debug.Enabled = !Debug.Enabled;
|
Debug.Enabled = !Debug.Enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Rectangle> collisionTargets = world.CollisionTargets();
|
List<Rectangle> collisionTargets = world.CollisionTargets();
|
||||||
player.Update(gameTime, gamePad, collisionTargets);
|
player.Update(gameTime, gamePad, keyboard, collisionTargets);
|
||||||
|
|
||||||
camera.Update(gameTime, player.Position);
|
camera.Update(gameTime, player.Position);
|
||||||
|
|
||||||
|
@ -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) {
|
void UpdateFromInput(
|
||||||
if (gamePad[0].IsButtonDown(Buttons.A) && gamePad[1].IsButtonUp(Buttons.A) &&
|
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;
|
||||||
|
Loading…
Reference in New Issue
Block a user