Merge branch 'main' of git.semicolin.games:semicolin/sneak into HEAD

This commit is contained in:
Colin McMillen 2020-07-14 11:53:14 -04:00
commit d926d23b3f

View File

@ -75,8 +75,6 @@ namespace SemiColinGames {
public class Player { public class Player {
private readonly FSM<History<Input>> fsm; private readonly FSM<History<Input>> fsm;
// TODO: get rid of Pose.
private enum Pose { Walking, Standing, SwordSwing, Jumping };
// Details of the sprite image. // Details of the sprite image.
// player_1x is 48 x 48, yOffset=5, halfSize=(7, 14) // player_1x is 48 x 48, yOffset=5, halfSize=(7, 14)
@ -95,7 +93,6 @@ namespace SemiColinGames {
// Useful so that we can run at a slow time-step and still get non-zero motion. // Useful so that we can run at a slow time-step and still get non-zero motion.
private Vector2 residual = Vector2.Zero; private Vector2 residual = Vector2.Zero;
private Pose pose = Pose.Jumping;
private float invincibilityTime = 0; private float invincibilityTime = 0;
// For passing into Line.Rasterize() during movement updates. // For passing into Line.Rasterize() during movement updates.
@ -224,11 +221,6 @@ namespace SemiColinGames {
} else if (inputMovement.X < 0) { } else if (inputMovement.X < 0) {
Facing = -1; Facing = -1;
} }
if (inputMovement.X != 0) {
pose = Pose.Walking;
} else {
pose = Pose.Standing;
}
} }
// Returns the desired (dx, dy) for the player to move this frame. // Returns the desired (dx, dy) for the player to move this frame.
@ -238,24 +230,18 @@ namespace SemiColinGames {
return ((IPlayerState) fsm.State).Movement; return ((IPlayerState) fsm.State).Movement;
} }
private Rectangle GetTextureSource(Pose pose) { private Rectangle GetTextureSource() {
double time = Clock.ModelTime.TotalSeconds; double time = Clock.ModelTime.TotalSeconds;
switch (pose) { IPlayerState state = (IPlayerState) fsm.State;
case Pose.Walking: if (StandingOnGround && state.Movement.X == 0) {
case Pose.Jumping: return Sprites.Ninja.GetTextureSource("idle", time);
return Sprites.Ninja.GetTextureSource("run", time); } else {
case Pose.SwordSwing: return Sprites.Ninja.GetTextureSource("run", time);
// TODO: make a proper animation class & FSM-driven animations.
//return Sprites.Ninja.GetTextureSource(
// "attack_sword", 0.3 - swordSwingTime);
case Pose.Standing:
default:
return Sprites.Ninja.GetTextureSource("idle", time);
} }
} }
public void Draw(SpriteBatch spriteBatch) { public void Draw(SpriteBatch spriteBatch) {
Rectangle textureSource = GetTextureSource(pose); Rectangle textureSource = GetTextureSource();
Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset); Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset);
SpriteEffects effect = Facing == 1 ? SpriteEffects effect = Facing == 1 ?
SpriteEffects.None : SpriteEffects.FlipHorizontally; SpriteEffects.None : SpriteEffects.FlipHorizontally;