package personnage;

import java.util.ArrayList;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;


public class Balles 
{
	ArrayList <Balle> delta;
	
	public Balles()
	{
		delta = new ArrayList <Balle>() ;
	}
	public void add(int x, int y, int id, int direction, int vy) throws SlickException
	{
		delta.add(new Balle(x,y,(direction == 1)?8:-8, vy, id));
	}
	public void update()
	{
		for(int i=0;i<delta.size();i++)
		{
			delta.get(i).update() ;
		}
	}
	public void draw(Graphics g)
	{
		for(int i=0;i<delta.size();i++)
		{
			delta.get(i).draw(g) ;
		}
	}
	public void test(ArrayList <Rectangle> boxs)
	{
		for(int i=0;i<delta.size();i++)
		{
			delta.get(i).update() ;
			if(delta.get(i).destroy(boxs))
			{
				delta.remove(i) ;
			}
		}	
	}
	public void test(Personnage perso)
	{
		Rectangle rect = new Rectangle(perso.x, perso.y, 22,32) ;
		for(int i=0 ; i < delta.size() ; i++)
		{
			if(delta.get(i).intersects(rect))
			{
				if(perso.armure > 0)
					perso.armure = (perso.armure-10 < 0)?0:perso.armure-10;
				else
				{
					perso.vie -= 1;
				}
				delta.remove(i) ;		
			}
		}
	}
	public void test(Zombie zomb)
	{
		Rectangle rect = new Rectangle(zomb.x, zomb.y, 22,32) ;
		for(int i=0 ; i < delta.size() ; i++)
		{
			if(delta.get(i).intersects(rect))
			{	
				zomb.vie -= 10;
				delta.remove(i) ;		
			}
		}
	}
}
