package shoot;

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

import enemis.Asteroid;
import menus.GameMenu;

public class DestroyerShoot extends BasicShoot{

	private float cpt;
	
	public DestroyerShoot(float x, float y, float dx, float dy) {
		super(x, y, dx, dy);
		cpt = 140f;
	}
	
	@Override
	public void update(GameMenu game){
		cpt--;
		if(cpt<0){
			destroy = true;
		}else{
			super.update(game);
		}
		if(Math.random()<0.2){
			game.getAnimations().add(new GameAnimation(GameAnimation.ANIM_DESTROYER_SHOOT,x+4,y));
		}
		
		if(game.getHunter01().onShootContact(game, this)){
			this.destroy = true;
			addDestroyAnimation(game);
		}else if(game.getHunter02().onShootContact(game, this)){
			this.destroy = true;
			addDestroyAnimation(game);
		}else if(game.getSupplyShip().onShootContact(game, this)){
			this.destroy = true;
			addDestroyAnimation(game);
		}
	}

	@Override
	public void renderShoot(GameMenu game) {
		if(!destroy){
			if(cpt<20){
				Shared.GAME_BATCH.setColor(1, 1, 1, (cpt/20f));
			}
			Shared.GAME_BATCH.draw(Shared.SHOOT_DESTROYER1, x-4+Shared.DECAL_X, y-4+Shared.DECAL_X);
			Shared.GAME_BATCH.setColor(1, 1, 1, 1);
		}
	}
	
	private void addDestroyAnimation(GameMenu game){
		game.getAnimations().add(new GameAnimation(GameAnimation.ANIM_DESTROYER_EXPLOSION, 
				(float)(x-8+(Math.random()*16))+Shared.DECAL_X, (float)(y-8+(Math.random()*12))+Shared.DECAL_Y));
	}

}
