HealthBarRenderSystem.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using Artemis;
  3. using StarWarrior.Components;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Graphics;
  6. namespace StarWarrior.Systems
  7. {
  8. public class HealthBarRenderSystem : EntityProcessingSystem {
  9. private SpriteBatch spriteBatch;
  10. private ComponentMapper<Health> healthMapper;
  11. private ComponentMapper<Transform> transformMapper;
  12. private SpriteFont font;
  13. public HealthBarRenderSystem(SpriteBatch spriteBatch,SpriteFont font) : base(typeof(Health), typeof(Transform)) {
  14. this.spriteBatch = spriteBatch;
  15. this.font = font;
  16. }
  17. public override void Initialize() {
  18. healthMapper = new ComponentMapper<Health>(world);
  19. transformMapper = new ComponentMapper<Transform>(world);
  20. }
  21. public override void Process(Entity e) {
  22. Health health = healthMapper.Get(e);
  23. Transform transform = transformMapper.Get(e);
  24. Vector2 textPosition = new Vector2((float)transform.GetX()-10, (float)transform.GetY()-30);
  25. spriteBatch.DrawString(font,health.GetHealthPercentage() + "%",textPosition,Color.White);
  26. }
  27. }
  28. }