|
|
@ -231,36 +231,26 @@ namespace SemiColinGames { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private int SpriteIndex(Pose pose) { |
|
|
|
int frameNum = (int) Clock.ModelTime.TotalMilliseconds / 125 % 4; |
|
|
|
private Rectangle GetTextureSource(Pose pose) { |
|
|
|
int time = (int) Clock.ModelTime.TotalMilliseconds; |
|
|
|
switch (pose) { |
|
|
|
case Pose.Walking: |
|
|
|
return 35 + frameNum; |
|
|
|
case Pose.Jumping: |
|
|
|
return 35 + frameNum; |
|
|
|
return Sprites.Ninja.GetTextureSource("run", time); |
|
|
|
case Pose.SwordSwing: |
|
|
|
if (swordSwingTime > 0.2) { |
|
|
|
return 0 + swordSwingNum * 3; |
|
|
|
} else if (swordSwingTime > 0.1) { |
|
|
|
return 1 + swordSwingNum * 3; |
|
|
|
} else { |
|
|
|
return 2 + swordSwingNum * 3; |
|
|
|
} |
|
|
|
// TODO: make a proper animation class & FSM-driven animations.
|
|
|
|
return Sprites.Ninja.GetTextureSource( |
|
|
|
"attack_sword", (int) (1000 * (0.3 - swordSwingTime))); |
|
|
|
case Pose.Crouching: |
|
|
|
case Pose.Stretching: |
|
|
|
case Pose.Standing: |
|
|
|
default: { |
|
|
|
if (frameNum == 3) { |
|
|
|
frameNum = 1; |
|
|
|
} |
|
|
|
return 29 + frameNum; |
|
|
|
} |
|
|
|
default: |
|
|
|
return Sprites.Ninja.GetTextureSource("idle", time); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void Draw(SpriteBatch spriteBatch) { |
|
|
|
int index = SpriteIndex(pose); |
|
|
|
Rectangle textureSource = new Rectangle(index * spriteWidth, 0, spriteWidth, spriteHeight); |
|
|
|
Rectangle textureSource = GetTextureSource(pose); |
|
|
|
Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset); |
|
|
|
SpriteEffects effect = Facing == 1 ? |
|
|
|
SpriteEffects.None : SpriteEffects.FlipHorizontally; |
|
|
@ -268,7 +258,7 @@ namespace SemiColinGames { |
|
|
|
if (invincibilityTime > 0 && invincibilityTime % 0.2f > 0.1f) { |
|
|
|
color = new Color(0.5f, 0.5f, 0.5f, 0.5f); |
|
|
|
} |
|
|
|
spriteBatch.Draw(Textures.Player.Get, position.ToVector2(), textureSource, color, 0f, |
|
|
|
spriteBatch.Draw(Textures.Ninja.Get, position.ToVector2(), textureSource, color, 0f, |
|
|
|
spriteCenter, Vector2.One, effect, 0f); |
|
|
|
} |
|
|
|
} |
|
|
|