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

  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. private int SpriteIndex() {
  23. int frameNum = (int) Clock.ModelTime.TotalMilliseconds / 125 % 4;
  24. return 35 + frameNum;
  25. }
  26. public void Draw(SpriteBatch spriteBatch) {
  27. int index = SpriteIndex();
  28. Rectangle textureSource = new Rectangle(index * spriteWidth, 0, spriteWidth, spriteHeight);
  29. Vector2 spriteCenter = new Vector2(spriteWidth / 2, spriteHeight / 2 + spriteCenterYOffset);
  30. SpriteEffects effect = Facing == 1 ?
  31. SpriteEffects.None : SpriteEffects.FlipHorizontally;
  32. Color color = Color.White;
  33. spriteBatch.Draw(Textures.Executioner.Get, position.ToVector2(), textureSource, color, 0f,
  34. spriteCenter, Vector2.One, effect, 0f);
  35. }
  36. }
  37. }