add sword swing

GitOrigin-RevId: 46ebf8496eca9d752eeec6d3a2fad202a8f33867
This commit is contained in:
Colin McMillen 2019-12-08 09:48:29 -05:00
parent fdd0eb60c4
commit 050a5b0567

View File

@ -6,24 +6,30 @@ using System;
namespace Jumpy {
class Player {
enum Facing { Left, Right };
enum Pose { Walking, Standing, Crouching, Stretching };
enum Pose { Walking, Standing, Crouching, Stretching, SwordSwing };
private const int spriteSize = 144;
private const int spriteWidth = 20;
private const int moveSpeed = 600;
private Texture2D texture;
// TODO: stop assuming 1920x1080.
private Vector2 position = new Vector2(200, 1080 - spriteSize / 2);
private Facing facing = Facing.Right;
private Pose pose = Pose.Standing;
private Texture2D texture;
private double swordSwingTime = 0;
public Player(Texture2D texture) {
this.texture = texture;
}
public void Update(GameTime gameTime, GamePadState gamePadState) {
Vector2 leftStick = gamePadState.ThumbSticks.Left;
public void Update(GameTime gameTime, GamePadState gamePad) {
if (gamePad.Buttons.X == ButtonState.Pressed && swordSwingTime <= 0) {
swordSwingTime = 0.3;
pose = Pose.SwordSwing;
return;
}
Vector2 leftStick = gamePad.ThumbSticks.Left;
if (leftStick.X < -0.5) {
facing = Facing.Left;
pose = Pose.Walking;
@ -39,6 +45,12 @@ namespace Jumpy {
} else {
pose = Pose.Standing;
}
if (swordSwingTime > 0) {
swordSwingTime -= gameTime.ElapsedGameTime.TotalSeconds;
pose = Pose.SwordSwing;
}
position.X = Math.Min(Math.Max(position.X, 0 + spriteWidth), 1920 - spriteWidth);
}
@ -54,6 +66,14 @@ namespace Jumpy {
return new Point(spriteSize * 7, spriteSize * 2);
case Pose.Stretching:
return new Point(spriteSize * 1, spriteSize * 2);
case Pose.SwordSwing:
if (swordSwingTime > 0.2) {
return new Point(spriteSize * 3, 0);
} else if (swordSwingTime > 0.1) {
return new Point(spriteSize * 4, 0);
} else {
return new Point(spriteSize * 5, 0);
}
case Pose.Standing:
default:
return new Point(spriteSize * 7, 0);