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.

46 lines
1.4 KiB

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