package ei.game.scene.weapons;

import ei.engine.effects.Particles;
import ei.engine.math.Vector2f;
import ei.engine.math.Vector2i;
import ei.game.gamestate.InGameState;
import ei.game.network.entities.NetworkWepon;
import ei.game.scene.Map;

/**
 * Handles the bomber units webon
 * @author Jesper Lundin
 *
 */
public class BomberWeapon extends NetworkWepon{
	private Particles part;
	private boolean hit;
	private Vector2i position;
	
	public BomberWeapon(Vector2f startPos) {
		super(startPos);
		setVelocity(4);
		setRange(100);
		setDamage(40);
		setReload(150);
		hit = false;
		position = Map.getPosByPixel(startPos.getX(), startPos.getY());
	}
	
	public Particles getWeapon() {
		part = new Particles("bomber");
		part = new Particles("weapon");
		part.MaxSpeedX=700;
		part.MaxSpeedY=700;
		part.MaxSpeedZ=0;
		part.slowdown = 1;
		part.rainbow = false;
		part.regenerate = false;
		part.size=10;
		float colors[][][]=       // Rainbow Of Colors
	    {
	        {{0.5f,0.5f,1.0f},{0.5f,0.5f,1.0f}}
	        
	    };
		part.colors = colors;
		return part;
	}
	
	public void update() {
		
		if(!hit)  {
			for(int i=position.getX()-1; i<=position.getX()+1; i++ ) {
				for(int j=position.getY()-1; j<=position.getY()+1; j++) {
					System.out.println("i :"+i+" j: "+j);
					if(InGameState.getMap().posExist(i, j)&& !InGameState.getMap().isPosEmpty(i, j)) {
						System.out.println("Damaged");
						InGameState.getMap().getPos(i, j).damaged(getDamage());
					}
				}
			}
			hit = true;
		}
		if(part.isDead()) {
			WeaponHandler.getInstance().removeWeapon(this);
		}
		
	}

}
