package zero1hd.rhythmbullet.entity.enemies;

import java.util.HashMap;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle;

import zero1hd.rhythmbullet.entity.Entity;
import zero1hd.rhythmbullet.entity.ally.Laser;

public class Shard extends Entity {
	private int hp;
	private int maxHp;
	
	@Override
	public void preInit() {
		sprite = new Sprite(assets.get("shard.png", Texture.class));
		setSize(2f, 2f);
		sprite.setSize(3f, 2f);
		simple = false;
		enemy = true;
		super.preInit();
	}
	
	public void init(float x, float y, float angle, float rate, int hp) {
		speed = rate;
		this.hp = hp;
		maxHp = hp;
		this.angle = angle;
		setPosition(x-(getWidth()/2f), y-(getHeight()/2f));
		hitbox.setSize(getWidth(), getHeight());
	}
	
	/**
	 * x, y, angle, rate, hp;
	 */
	@Override
	public void init(HashMap<String, Float> params) {
		setX(params.get("x"));
		setY(params.get("y"));
		angle = params.get("angle");
		speed = params.get("rate");
		hp = params.get("hp").intValue();
		super.init(params);
	}
	
	@Override
	public void reset() {
		hp = 0;
		maxHp = 0;
		super.reset();
	}
	
	@Override
	public void act(float delta) {
		if (hp <= 0) {
			dead = true;
		}
		super.act(delta);
	}
	
	@Override
	public void draw(Batch batch, float parentAlpha) {
		sprite.setColor(((float)hp/(float)maxHp), ((float)hp/(float)maxHp), ((float)hp/(float)maxHp), 0.5f);
		super.draw(batch, parentAlpha);
	}
	
	@Override
	public void collided(Entity entity) {
		if (entity.getClass() == Laser.class) {
			hp --;
		} else {
			dead = true;
		}
	}

	@Override
	public Rectangle getHitZone() {
		return hitbox;
	}

}
