package levelElements;

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;

import Global.Global;
import effects.HealthBar;

public class Shipv1 extends Sprite {// this is a very simple, non animated sprite. Is this the lightest thing I have?
	private TextureRegion main;
	private TextureRegion broken;
	private Texture t1;
	public Color color;
	public Rectangle rect;
	public boolean isBroken;
	private int _sw;// sprite width
	private int _sh;// sprite height
	public HealthBar healthBar;

	public Shipv1(float _x, float _y) {
		rect = new Rectangle();
		rect.x = (int) _x;
		rect.y = (int) _y;
		rect.width = 100;
		rect.height = 100;
		_sw = 100;
		_sh = 100;
		healthBar = new HealthBar(_x, _y, 100, 2);
		// still frames
		t1 = new Texture(Gdx.files.internal("shipv1.png"));
		main = new TextureRegion(t1, (0 * _sw), (0 * _sh), _sw, _sh);
		broken = new TextureRegion(t1, (1 * _sw), (0 * _sh), _sw, _sh);
		color = Color.WHITE;
		setBounds(0, 0, _sw, _sh);
		setOriginCenter();
		setRegion(main);
	}

	private void update() {
		rect.x = Global.P.x - 45;
		rect.y = Global.P.y - 30;
	}

	public TextureRegion getFrame(OrthographicCamera camera, float dt) {
		update();
		return getTextureRegion();
	}

	public TextureRegion getTextureRegion() {
		if (isBroken)
			return broken;
		else
			return main;
	}

	public void render(ddd game, OrthographicCamera camera, float dt) {// hmmm i think it just needs placed before? it gets here.
		game.batch.setColor(color);
		game.batch.draw(getFrame(camera, dt), rect.x, rect.y);
	}

	public void dispose() {
	}
}
