diff --git a/Shared/Player.cs b/Shared/Player.cs index a2a3f1b..0e3a758 100644 --- a/Shared/Player.cs +++ b/Shared/Player.cs @@ -75,8 +75,6 @@ namespace SemiColinGames { public class Player { private readonly FSM> fsm; - // TODO: get rid of Pose. - private enum Pose { Walking, Standing, SwordSwing, Jumping }; // Details of the sprite image. // 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. private Vector2 residual = Vector2.Zero; - private Pose pose = Pose.Jumping; private float invincibilityTime = 0; // For passing into Line.Rasterize() during movement updates. @@ -224,11 +221,6 @@ namespace SemiColinGames { } else if (inputMovement.X < 0) { 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. @@ -238,24 +230,18 @@ namespace SemiColinGames { return ((IPlayerState) fsm.State).Movement; } - private Rectangle GetTextureSource(Pose pose) { + private Rectangle GetTextureSource() { double time = Clock.ModelTime.TotalSeconds; - switch (pose) { - case Pose.Walking: - case Pose.Jumping: - return Sprites.Ninja.GetTextureSource("run", time); - case Pose.SwordSwing: - // 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); + IPlayerState state = (IPlayerState) fsm.State; + if (StandingOnGround && state.Movement.X == 0) { + return Sprites.Ninja.GetTextureSource("idle", time); + } else { + return Sprites.Ninja.GetTextureSource("run", time); } } public void Draw(SpriteBatch spriteBatch) { - Rectangle textureSource = GetTextureSource(pose); + Rectangle textureSource = GetTextureSource(); Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset); SpriteEffects effect = Facing == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;