41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
namespace SemiColinGames {
|
|
class NPC {
|
|
private Point position;
|
|
|
|
private const int spriteWidth = 96;
|
|
private const int spriteHeight = 81;
|
|
private const int spriteCenterYOffset = 3;
|
|
|
|
public NPC(Point position) {
|
|
this.position = position;
|
|
}
|
|
|
|
public int Facing { get; private set; } = 1;
|
|
|
|
public void Update(float modelTime) {
|
|
if (Facing == 1 && position.X > 16 * 39) {
|
|
Facing = -1;
|
|
}
|
|
if (Facing == -1 && position.X < 16 * 24) {
|
|
Facing = 1;
|
|
}
|
|
position.X += (int) (120 * Facing * modelTime);
|
|
}
|
|
|
|
public void Draw(SpriteBatch spriteBatch) {
|
|
Rectangle textureSource = Sprites.Executioner.GetTextureSource(
|
|
"run", (int) Clock.ModelTime.TotalMilliseconds);
|
|
// 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;
|
|
spriteBatch.Draw(Textures.Executioner.Get, position.ToVector2(), textureSource, color, 0f,
|
|
spriteCenter, Vector2.One, effect, 0f);
|
|
}
|
|
}
|
|
}
|