Player.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 Tutorial026.Managers;
  10. using Tutorial026.Models;
  11. namespace Tutorial026.Sprites
  12. {
  13. public class Player : Sprite
  14. {
  15. private AttributesManager _attributeManager;
  16. /// <summary>
  17. /// These are the types of attributes to only change on level-up
  18. /// </summary>
  19. public Attributes BaseAttributes { get; set; }
  20. /// <summary>
  21. /// These are extra attributes that can be gained from different sources (equipment, power-ups, spells etc)
  22. /// </summary>
  23. public List<Attributes> AttributeModifiers { get; set; }
  24. public Attributes TotalAttributes
  25. {
  26. get
  27. {
  28. return BaseAttributes + AttributeModifiers.Sum();
  29. }
  30. }
  31. public Player(Texture2D texture)
  32. : base(texture)
  33. {
  34. BaseAttributes = new Attributes();
  35. AttributeModifiers = new List<Attributes>();
  36. _attributeManager = new AttributesManager(AttributeModifiers);
  37. }
  38. public override void Update(GameTime gameTime)
  39. {
  40. _attributeManager.Update(gameTime);
  41. }
  42. public override void OnCollide(Sprite sprite)
  43. {
  44. switch (sprite)
  45. {
  46. case PowerUp powerUp:
  47. PowerUpCollected(powerUp);
  48. break;
  49. default:
  50. break;
  51. throw new Exception("Unexpected sprite type: " + sprite.ToString());
  52. }
  53. }
  54. private void PowerUpCollected(PowerUp powerUp)
  55. {
  56. powerUp.IsRemoved = true;
  57. AttributeModifiers.Add(powerUp.Attributes);
  58. }
  59. }
  60. }