package shoot;

import com.jln.ld.GameAnimation;
import com.jln.ld.Shared;

import enemis.Asteroid;
import enemis.Destroyer;
import menus.GameMenu;

public class HunterShoot extends BasicShoot{

	private float cpt;
	private boolean hunter2 = false;
	
	public HunterShoot(float x, float y, float dx, float dy, boolean hunter2) {
		super(x, y, dx, dy);
		cpt = 80f;
		this.hunter2 = hunter2;
	}
	
	@Override
	public void update(GameMenu game){
		cpt--;
		if(cpt<0 || x>640){
			destroy = true;
		}else{
			super.update(game);
		}
		
		for (Asteroid a : game.getAsteroids()) {
			if(a.onShootContact(game, this,true )){
				this.destroy = true;
				addDestroyAnimation(game,a.isDestroy());
			}
		}
		for (Destroyer d : game.getEnemis()) {
			if(d.onShootContact(game, this,true )){
				this.destroy = true;
				addDestroyAnimation(game,d.isDestroy());
			}
		}
	}

	@Override
	public void renderShoot(GameMenu game) {
		if(!destroy){
			if(cpt<20){
				Shared.GAME_BATCH.setColor(1, 1, 1, (cpt/20f));
			}
			Shared.GAME_BATCH.draw(hunter2?Shared.SHOOT_HUNTER2:Shared.SHOOT_HUNTER, x-4, y-4);
			Shared.GAME_BATCH.setColor(1, 1, 1, 1);
		}
	}
	
	private void addDestroyAnimation(GameMenu game, boolean destroy){
		if(destroy){
			Shared.SOUND_EXPLOSE.play();
		}else{
			Shared.SOUND_HIT.play();
		}
		
		game.getAnimations().add(new GameAnimation(GameAnimation.ANIM_EXPLOSION, 
				(float)(x-8+(Math.random()*16))+Shared.DECAL_X, (float)(y-8+(Math.random()*12))+Shared.DECAL_Y));
		if(destroy){
			game.getAnimations().add(new GameAnimation(GameAnimation.ANIM_EXPLOSION, 
					(float)(x-8+(Math.random()*16))+Shared.DECAL_X, (float)(y-8+(Math.random()*12))+Shared.DECAL_Y));
			Shared.DECAL_Y = 4;
			Shared.CPT_DECAL = 3;
		}
	}

}
