public MilitaryBase(ResourceManager res) { maxHealth = 100f; health = maxHealth; point = Vector2.Zero; radius = 450f; healthbar = new GameObject(res.healthbar); foreground = new GameObject(res.healthbarforeground); healthbarbg = new GameObject(res.healthbarbg); Vector2 p = new Vector2((MyGame.WIDTH - foreground.getWidth()) / 2, 10); foreground.setPos(p); healthbar.setPos(new Vector2(p.x, p.y)); healthbarbg.setPos(p); healthbar.setOrigin(new Vector2(0, 0)); fullWidth = healthbar.getWidth(); }
public void render(SpriteBatch batch) { healthbarbg.render(batch); healthbar.render(batch); foreground.render(batch); }
public void takeDamage(float damage) { health -= damage; healthbar.setSource(new Rectangle(0, 0, fullWidth * health / maxHealth, healthbar.getHeight())); }