A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

44 lines
1.3 KiB

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