package zero1hd.rhythmbullet.entity.ally;

import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.math.Rectangle;

import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.entity.Entity;

public class PolyjetEntity extends Entity {
	public float health;
	private ParticleEffect thrust;
	private Texture polyjet;
	private ParticleEffect teleportCloak;
	public boolean moveLeft, moveRight, moveUp, moveDown, teleporting, accelerate;
	private float speed, accel;
	private float rate;
	private int maxH;
	public PolyjetEntity(AssetManager assets, float speed, float accel,int maxHealth, String jet) {
		health = 100;
		this.speed = speed;
		this.accel = accel;
		setSize(1.5f, 1.5f);
		setPosition(RhythmBullet.WORLD_WIDTH/2 - getWidth()/2, -4f);
		maxH = maxHealth;
		hitbox = new Rectangle(getX(), getY(), getWidth(), getHeight());
		polyjet = assets.get("polyjet-" + jet + ".png", Texture.class);
		thrust = assets.get("standard_thrust.p", ParticleEffect.class);
		thrust.start();
		
		teleportCloak = assets.get("teleport-cloak.p", ParticleEffect.class);
		
	}
	
	@Override
	public void calculate(float delta) {
		hitbox.setPosition(getX(), getY());
		
		thrust.setPosition(getX()+(getWidth())/2 - 1f/16f, getY()-0.2f);
		thrust.update(delta);
		teleportCloak.setPosition(getX() +(getWidth()-1)/2, getY() + (getHeight()-1)/2);
		
		hitbox.setPosition(getX(), getY());
		
		//Movement!
		if (accelerate) {
			rate = speed + accel;
		} else {
			rate = speed;
		}
		
		if (moveLeft && !moveRight) {
			moveBy(-(rate*delta), 0);
		}
		if (moveRight && !moveLeft) {
			moveBy(rate*delta, 0);
		}
		if (moveUp && !moveDown) {
			moveBy(0, rate*delta);
		}
		
		if (moveDown && !moveUp) {
			moveBy(0, -rate*delta);
		}
		
		if (health <= 0) {
			dead = true;
		} else if (health > maxH) {
			health = maxH;
		}
		
		super.calculate(delta);
	}
	
	@Override
	public void draw(Batch batch) {
		thrust.draw(batch);
		batch.draw(polyjet, getX(), getY(), getWidth(), getHeight());
		super.draw(batch);
	}

	@Override
	public void collided(Entity entity) {
	}
	
	public Rectangle getHitbox() {
		return hitbox;
	}
	
	public void setHealth(float health) {
		this.health = health;
	}
}
