package effects;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import com.ld57.game.ddd;

public class HealthBar extends Sprite {// this is a very simple, non animated sprite.

	private TextureRegion main;
	private Texture t1;
	public Color color;
	private Rectangle rect;
	private int _sw;// sprite width
	private int _sh;// sprite height
	private int barWidth;
	private int barHeight;

	/*
	 * @_x this is hmmm
	 */
	public HealthBar(float _x, float _y, float _barWidth, float _barHeight) {
		rect = new Rectangle();
		barWidth = (int) _barWidth;
		barHeight = (int) _barHeight;
		rect.x = (int) _x;
		rect.y = (int) _y;
		rect.width = 100;
		rect.height = 5;

		_sw = 1;
		_sh = 1;

		// still frames
		t1 = new Texture(Gdx.files.internal("onePixel.png"));
		main = new TextureRegion(t1, (0 * _sw), (0 * _sh), _sw, _sh);
		color = Color.GREEN;
		setBounds(0, 0, _sw, _sh);
		setOriginCenter();
		setRegion(main);
	}

	private void update(float __x, float __y) {
		rect.x = __x - 10;
		rect.y = __y + 45;
	}

	public TextureRegion getTextureRegion() {
		return main;
	}

	public void render(ddd game, OrthographicCamera camera, float dt, float personRectXToFollow, float personRectYToFollow, int health, int healthMax) {
		update(personRectXToFollow, personRectYToFollow);
		float w = ((float) health / healthMax) * barWidth;
		if (health >= healthMax / 2)
			color = Color.GREEN;
		if (health < healthMax / 2)
			color = Color.YELLOW;
		if (health <= healthMax / 3)
			color = Color.ORANGE;
		if (health <= healthMax / 6)
			color = Color.RED;
		game.batch.setColor(color);
		game.batch.draw(getTextureRegion(), rect.x, rect.y, w, barHeight);
	}

	public void dispose() {
	}
}
