|
|
@ -0,0 +1,46 @@ |
|
|
|
using Microsoft.Xna.Framework; |
|
|
|
using Microsoft.Xna.Framework.Graphics; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
private int SpriteIndex() { |
|
|
|
int frameNum = (int) Clock.ModelTime.TotalMilliseconds / 125 % 4; |
|
|
|
return 35 + frameNum; |
|
|
|
} |
|
|
|
|
|
|
|
public void Draw(SpriteBatch spriteBatch) { |
|
|
|
int index = SpriteIndex(); |
|
|
|
Rectangle textureSource = new Rectangle(index * spriteWidth, 0, spriteWidth, spriteHeight); |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |