package zero1hd.polyjet.entity.enemies;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Pool.Poolable;

import zero1hd.polyjet.Polyjet;
import zero1hd.polyjet.entity.Entities;
import zero1hd.polyjet.entity.Entity;

public class Bar extends Actor implements Entity, Poolable {
	private boolean dead;
	private Texture texture;
	private float rate;
	private Rectangle hitbox;
	
	public Bar(Texture barTexture) {
		this.texture = barTexture;
		hitbox = new Rectangle();
	}
	
	public void init(float x, float rate) {
		setSize(5f, 0.5f);
		setPosition(x, Polyjet.GAME_AREA_HEIGHT);
		this.rate = rate;
		hitbox.set(getX(), getY(), getWidth(), getHeight());
	}
	
	@Override
	public void act(float delta) {
		moveBy(0f, -delta*rate);
		hitbox.setPosition(getX(), getY());
		super.act(delta);
		if (getY() < 0-getHeight()) {
			dead = true;
		}
	}
	
	@Override
	public void draw(Batch batch, float parentAlpha) {
		batch.draw(texture, getX(), getY(), getWidth(), getHeight());
		super.draw(batch, parentAlpha);
	}
	
	@Override
	public void reset() {
		hitbox.set(0, 0, 0, 0);
		setPosition(0, 0);
		rate = 0;
		dead = false;
		setSize(0, 0);
	}

	@Override
	public void collided(Entity entity) {
		switch (entity.getEntityType()) {
		case POLYJET:
			dead = true;
			break;
		default:
			break;
		}
	}

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

	@Override
	public Entities getEntityType() {
		return Entities.BAR;
	}

	@Override
	public boolean isDead() {
		return dead;
	}

}
