HudRenderSystem.cs 991 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using Artemis;
  3. using StarWarrior.Components;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Graphics;
  6. using Microsoft.Xna.Framework.Content;
  7. using System.Collections.Generic;
  8. namespace StarWarrior.Systems
  9. {
  10. public class HudRenderSystem : TagSystem {
  11. private SpriteBatch spriteBatch;
  12. private ComponentMapper<Health> healthMapper;
  13. private SpriteFont font;
  14. public HudRenderSystem(SpriteBatch spriteBatch,SpriteFont font) : base("PLAYER") {
  15. this.spriteBatch = spriteBatch;
  16. this.font = font;
  17. }
  18. public override void Initialize() {
  19. healthMapper = new ComponentMapper<Health>(world);
  20. }
  21. public override void Process(Entity e) {
  22. Health health = healthMapper.Get(e);
  23. Vector2 textPosition = new Vector2(20, spriteBatch.GraphicsDevice.Viewport.Height);
  24. spriteBatch.DrawString(font, "Health: " + health.GetHealthPercentage() + "%", textPosition, Color.White);
  25. }
  26. }
  27. }