package Ship;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Animation.PlayMode;
import com.jln.ld.GameUtils;
import com.jln.ld.Shared;

import menus.GameMenu;
import shoot.EnergyShoot;
import shoot.HunterShoot;

public class SupplySpaceship extends BasicShip{

	private int cptShootSound = 0;
	public SupplySpaceship(float x, float y, boolean playerOnControl) {
		super(x, y, playerOnControl);
		
		this.width = 48;
		this.height = 48;
		this.speed = 3.1f;
		this.speedFactor = 0f;
		this.acceleration = 0.03f;
		this.energy = 5;
		this.maxEnergy = 5;
		this.iaSpeed = 1.4f;
		
	}

	@Override
	protected void initRessources(){
		this.moveAnimations = new Animation[4];
		moveAnimations[0] = GameUtils.loadAnimation(Shared.SHIP_SUPPLY, 3, 0, 0.12f, PlayMode.LOOP);
		moveAnimations[1] = GameUtils.loadAnimation(Shared.SHIP_SUPPLY, 3, 1, 0.12f, PlayMode.LOOP);
		moveAnimations[2] = GameUtils.loadAnimation(Shared.SHIP_SUPPLY, 3, 2, 0.12f, PlayMode.LOOP);
		moveAnimations[3] = GameUtils.loadAnimation(Shared.SHIP_SUPPLY, 3, 3, 0.12f, PlayMode.LOOP);
	}
	
	protected void updateControls(GameMenu game){
		super.updateControls(game);
		if(Gdx.input.isKeyPressed(Keys.SPACE)){
			shoot(game);
		}
	}
	
	protected void shoot(GameMenu game){
		super.shoot(game);
		if(cptShootSound<=0){
			playShootSound();
		}
		if(shootLevel == 0 || shootLevel == 2){
			game.addShoot(new EnergyShoot(x+18, y, 5, 0)); 
		}
		if(shootLevel == 1 || shootLevel == 2){
			game.addShoot(new EnergyShoot(x+14, y+14, 4.6f, 0.4f));
			game.addShoot(new EnergyShoot(x+14, y-14, 4.6f, -0.4f));
		}
	}
	
	public void update(GameMenu game){
		if(cptShootSound>0){
			cptShootSound--;
		}
		super.update(game);
	}
	

	/**
	 * ==========================================
	 * == DESSIN DE L'OBJET                    ==
	 * ==========================================
	 */
	@Override
	public void renderShip(GameMenu game) {
		if(dead){
			Shared.GAME_BATCH.draw(moveAnimations[3].getKeyFrame(statetime), (int)(x-(width/2))+Shared.DECAL_X, (int)(y-(height/2)+Shared.DECAL_Y));
		}else{
			Shared.GAME_BATCH.draw(moveAnimations[speedAnimation].getKeyFrame(statetime), (int)(x-(width/2))+Shared.DECAL_X, (int)(y-(height/2)+Shared.DECAL_Y));
		}
	}

	protected void playShootSound(){
		cptShootSound = 20;
		Shared.SOUND_HEAL.play();
	}
}
