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.

40 lines
1.2 KiB

  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. namespace SemiColinGames {
  4. class NPC {
  5. private Point position;
  6. private const int spriteWidth = 96;
  7. private const int spriteHeight = 81;
  8. private const int spriteCenterYOffset = 3;
  9. public NPC(Point position) {
  10. this.position = position;
  11. }
  12. public int Facing { get; private set; } = 1;
  13. public void Update(float modelTime) {
  14. if (Facing == 1 && position.X > 16 * 39) {
  15. Facing = -1;
  16. }
  17. if (Facing == -1 && position.X < 16 * 24) {
  18. Facing = 1;
  19. }
  20. position.X += (int) (120 * Facing * modelTime);
  21. }
  22. public void Draw(SpriteBatch spriteBatch) {
  23. Rectangle textureSource = Sprites.Executioner.GetTextureSource(
  24. "run", (int) Clock.ModelTime.TotalMilliseconds);
  25. // TODO: move this into Sprite metadata.
  26. Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset);
  27. SpriteEffects effect = Facing == 1 ?
  28. SpriteEffects.None : SpriteEffects.FlipHorizontally;
  29. Color color = Color.White;
  30. spriteBatch.Draw(Textures.Executioner.Get, position.ToVector2(), textureSource, color, 0f,
  31. spriteCenter, Vector2.One, effect, 0f);
  32. }
  33. }
  34. }