package org.egordorichev.lasttry.entity;

import org.egordorichev.lasttry.entity.components.*;
import org.egordorichev.lasttry.graphics.Graphics;
import org.egordorichev.lasttry.util.Util;

public class Creature extends Entity {
	public CreatureStatsComponent stats;
	public CreatureStateComponent state;
	public CreatureEffectsComponent effects;

	public Creature(CreaturePhysicsComponent physics, CreatureGraphicsComponent graphics) {
		super(physics, graphics);

		this.stats = new CreatureStatsComponent(this);
		this.state = new CreatureStateComponent(this);
		this.effects = new CreatureEffectsComponent(this);
	}

	public Creature() {
		this(new CreaturePhysicsComponent(), new CreatureGraphicsComponent());
	}

	@Override
	public void render() {
		super.render();

		if (this.stats.getHp() != this.stats.getMaxHP() && this.stats.getHp() != 0) {
			this.renderHealthBar();
		}
	}

	protected void renderHealthBar() {
		float hp = (float) this.stats.getHp() / (float) this.stats.getMaxHP();

		if (hp < 0.3f) {
			Graphics.batch.setColor(1, 0, 0, 1);
		} else if (hp < 0.6f) {
			Graphics.batch.setColor(1, 1, 0, 1);
		} else {
			Graphics.batch.setColor(0, 1, 0, 1);
		}

		int mapped = (int) Util.map(this.stats.getHp(), 0, this.stats.getMaxHP(), 0, 26);
		int x = (int) (this.physics.getX() + (this.physics.getSize().x - 28) / 2);

//		Graphics.batch.draw(Graphics.healthBarTexture, x + 2, this.physics.getY() - 20,
//			mapped, 12, 0, 0, mapped, 12, false, false);
//		Graphics.batch.setColor(1, 1, 1, 1);
//		Graphics.batch.draw(Graphics.healthBarFrameTexture, x, this.physics.getY() - 20);
	}

	@Override
	public void update(int dt) {
		super.update(dt);

		this.graphics.update(dt);
		this.stats.update(dt);

		if (this.stats.getHp() == 0) {
			this.die();
		}
	}
}
@@ -753,25 +753,278 @@
 %7B%0A%09%09
-super.render(
+// TODO: Should this reset be placed somewhere else in case the same%0A%09%09// logic applies to more than just creatures?%0A%09%09//%0A%09%09// Reset entity color.%0A%09%09// Prevents the previous entity's coloring from interfering with this%0A%09%09// one's.%0A%09%09Graphics.batch.setColor(1, 1, 1, 1
 );%0A
-%0A
 %09%09if
@@ -1130,16 +1130,34 @@
 ();%0A%09%09%7D%0A
+%09%09super.render();%0A
 %09%7D%0A%0A%09pro
@@ -1605,20 +1605,21 @@
  / 2);%0A%0A
-//
 %09%09
+// 
 Graphics
@@ -1663,16 +1663,21 @@
 , x + 2,
+%0A%09%09//
  this.ph
@@ -1699,13 +1699,13 @@
 20,%0A
-//%09%09%09
+%09%09// 
 mapp
@@ -1745,20 +1745,21 @@
 false);%0A
-//
 %09%09
+// 
 Graphics
@@ -1791,12 +1791,13 @@
 1);%0A
-//
 %09%09
+// 
 Grap
@@ -1846,16 +1846,21 @@
 ture, x,
+%0A%09%09//
  this.ph

Fix entity health color tinting bleeding into the rest of the entities and other rendered textures