Browse Source

Player: start using Sprite data to calculate texture source / animations.

master
Colin McMillen 4 years ago
parent
commit
0b8eb3e3f1
  1. 30
      Shared/Player.cs
  2. 21
      Shared/Sprites.cs
  3. 6
      Shared/Textures.cs

30
Shared/Player.cs

@ -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);
}
}

21
Shared/Sprites.cs

@ -4,6 +4,18 @@ using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace SemiColinGames {
static class Sprites {
public static Sprite Executioner;
public static Sprite Ninja;
public static void Load(ContentManager content) {
Executioner = new Sprite(
Textures.Executioner, content.LoadString("sprites/ccg/executioner_female.json"));
Ninja = new Sprite(
Textures.Ninja, content.LoadString("sprites/ccg/ninja_female.json"));
}
}
struct SpriteAnimation {
public readonly int Start;
public readonly int End;
@ -77,13 +89,4 @@ namespace SemiColinGames {
return frames[animation.End].Source;
}
}
static class Sprites {
public static Sprite Executioner;
public static void Load(ContentManager content) {
Executioner = new Sprite(
Textures.Executioner, content.LoadString("sprites/ccg/executioner_female.json"));
}
}
}

6
Shared/Textures.cs

@ -33,8 +33,11 @@ namespace SemiColinGames {
public static SpriteFont DebugFont;
public static SpriteFont BannerFont;
public static TextureRef Player = new TextureRef("sprites/ccg/ninja_female");
// Character spritesheets.
public static TextureRef Executioner = new TextureRef("sprites/ccg/executioner_female");
public static TextureRef Ninja = new TextureRef("sprites/ccg/ninja_female");
// UI sprites.
public static TextureRef Heart = new TextureRef("sprites/semicolin/heart");
// Backgrounds are indexed by draw order; the first element should be drawn furthest back.
@ -45,6 +48,7 @@ namespace SemiColinGames {
new TextureRef("backgrounds/szadiart/pf4/background4_day"),
};
// Background tiles.
public static TextureRef Cemetery = new TextureRef("tiles/anokolisa/cemetery");
public static TextureRef Crypt = new TextureRef("tiles/anokolisa/crypt");
public static TextureRef Dungeon = new TextureRef("tiles/anokolisa/dungeon");

Loading…
Cancel
Save