calculate spriteCenter more rigorously

This commit is contained in:
Colin McMillen 2020-03-11 14:19:27 -04:00
parent 36a72b938f
commit b4e644c2d4

View File

@ -47,10 +47,12 @@ namespace SemiColinGames {
}
public class NPC {
// TODO: load sprite sizes from metadata.
private const int spriteWidth = 96;
private const int spriteHeight = 81;
private const int spriteCenterYOffset = 10;
private readonly Vector2 eyeOffset = new Vector2(4, -3);
private const int spriteHeight = 82;
private const int groundPadding = 7;
private readonly Vector2 spriteCenter;
private readonly Vector2 eyeOffset = new Vector2(4, -9);
private readonly FSM<NPC> fsm;
private AABB physicsBox;
@ -58,6 +60,7 @@ namespace SemiColinGames {
public NPC(Point position, int facing) {
Position = position;
spriteCenter = new Vector2(spriteWidth / 2, spriteHeight - halfSize.Y - groundPadding);
physicsBox = new AABB(position.ToVector2(), halfSize);
Facing = facing;
fsm = new FSM<NPC>(new Dictionary<string, IState<NPC>> {
@ -103,8 +106,6 @@ namespace SemiColinGames {
public void Draw(SpriteBatch spriteBatch) {
Rectangle textureSource = Sprites.Executioner.GetTextureSource(
fsm.StateName, Clock.ModelTime.TotalSeconds);
// TODO: move this into Sprite metadata.
Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset);
SpriteEffects effect = Facing == 1 ?
SpriteEffects.None : SpriteEffects.FlipHorizontally;
Color color = Color.White;