package zero1hd.polyjet.entity;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;

import zero1hd.polyjet.Polyjet;

public class PolyJetEntity extends Actor {
	
	private ParticleEffect thrust;
	private Texture polyjet;
	private ParticleEffect teleportCloak;
	
	
	public boolean moveLeft, moveRight, moveUp, moveDown, teleporting;
	private int rate;
	public PolyJetEntity(Polyjet core, int rate, String jet) {
		this.rate = rate;
		
		setSize(1.5f, 1.5f);
		
		setPosition(Polyjet.GAME_AREA_WIDTH/2 - getWidth()/2, -4f);
		
		polyjet = core.getAssetManager().get("polyjet-" + jet + ".png", Texture.class);
		thrust = core.getAssetManager().get("standard_thrust.p", ParticleEffect.class);
		thrust.start();
		
		teleportCloak = core.getAssetManager().get("teleport-cloak.p", ParticleEffect.class);
		
		addAction(Actions.moveTo(getX(), 4f, 0.5f));
	}
	
	@Override
	public void act(float delta) {
		thrust.setPosition(getX()+(getWidth())/2 - 1f/16f, getY()-0.15f);
		thrust.update(delta);
		teleportCloak.setPosition(getX() +(getWidth()-1)/2, getY() + (getHeight()-1)/2);
		
		super.act(delta);
		
		//Movement!
		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);
		}
		
	}
	
	@Override
	public void draw(Batch batch, float parentAlpha) {
		thrust.draw(batch);
		batch.draw(polyjet, getX(), getY(), getWidth(), getHeight());
		super.draw(batch, parentAlpha);

	}
}
