package shoot;

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

import enemis.Asteroid;
import menus.GameMenu;

public class EnergyShoot extends BasicShoot{

	private float cpt;
	
	public EnergyShoot(float x, float y, float dx, float dy) {
		super(x, y, dx, dy);
		cpt = 20f;
	}
	
	@Override
	public void update(GameMenu game){
		cpt--;
		if(cpt<0){
			destroy = true;
		}else{
			super.update(game);
		}
		
		if(game.getHunter01().onEnergyContact(game,this)){
			this.destroy =true;
			this.addDestroyAnimation(game);
		}
		if(game.getHunter02().onEnergyContact(game,this)){
			this.destroy =true;
			this.addDestroyAnimation(game);
		}

		for (Asteroid a : game.getAsteroids()) {
			if(a.onShootContact(game,this,false)){
				this.destroy = true;
				this.addDestroyAnimation(game);
			}
		}
	}

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

}
