Player.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Graphics;
  8. using Microsoft.Xna.Framework.Input;
  9. using Tutorial025.Models;
  10. namespace Tutorial025.Sprites
  11. {
  12. public class Player : Sprite
  13. {
  14. /// <summary>
  15. /// These are the types of attributes to only change on level-up
  16. /// </summary>
  17. public Attributes BaseAttributes { get; set; }
  18. /// <summary>
  19. /// These are extra attributes that can be gained from different sources (equipment, power-ups, spells etc)
  20. /// </summary>
  21. public List<Attributes> AttributeModifiers { get; set; }
  22. public Attributes TotalAttributes
  23. {
  24. get
  25. {
  26. return BaseAttributes + AttributeModifiers.Sum();
  27. }
  28. }
  29. public Player(Texture2D texture)
  30. : base(texture)
  31. {
  32. BaseAttributes = new Attributes();
  33. AttributeModifiers = new List<Attributes>();
  34. }
  35. public override void Update(GameTime gameTime)
  36. {
  37. var speed = TotalAttributes.Speed;
  38. var velocity = new Vector2();
  39. if (Keyboard.GetState().IsKeyDown(Keys.D))
  40. velocity.X = speed;
  41. else if (Keyboard.GetState().IsKeyDown(Keys.A))
  42. velocity.X = -speed;
  43. Position += velocity;
  44. }
  45. }
  46. }