package zero1hd.polyjet.entity.ally;

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 Laser extends Actor implements Entity, Poolable {
	private Rectangle hitBox;
	private float rate;
	boolean dead;
	Texture laserTexture;
	
	public Laser(Texture laserTexture) {
		this.laserTexture = laserTexture;
		setSize(0.25f, 2f);
	}
	
	public void init(float x, float y, float rate) {
		setX(x);
		setY(y);
		this.rate = rate;
		hitBox = new Rectangle();
		hitBox.setSize(getWidth(), getHeight());
		toBack();
	}
	
	@Override
	public void act(float delta) {
		toBack();
		moveBy(0, delta*rate);
		hitBox.setX(getX());
		hitBox.setY(getY());
		super.act(delta);
		
		if (getY() > Polyjet.GAME_AREA_HEIGHT) {
			dead = true;
		}
	}
	
	@Override
	public void draw(Batch batch, float parentAlpha) {
		batch.draw(laserTexture ,getX(), getY(), getWidth(), getHeight());
		super.draw(batch, parentAlpha);
	}
	
	@Override
	public void reset() {
		setX(0);
		setY(0);
		rate = 0;
		hitBox.set(0, 0, 0, 0);
		dead = false;
	}

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

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

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

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

}
