package personnage;

import java.util.ArrayList;

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

public class Balle 
{
	int x, y, vx, id, vy;
	Image image;
	
	public Balle(int x, int y, int vx, int vy, int id) throws SlickException
	{
		try
		{
		image = new Image("res/Armes/balle.png");
		}
		catch (RuntimeException e)
		{
			image = new Image("res/Armes/balle.png");
		}
		this.x = x;
		this.y = y;
		this.vx = vx;
		this.vy = vy;
		this.id = id;
	}	
	
	public void update()
	{
		x += vx;
		y += vy;
	}
	public boolean destroy(ArrayList<Rectangle> boxs)
	{
		Rectangle rect = new Rectangle(x,y,10,3);
		for(int i=0;i<boxs.size();i++)
			if(boxs.get(i).intersects(rect))
				return true;
		return (x < -3 || x > 800) || (y < -3 || y > 640);
		
	}
	public void draw(Graphics g)
	{
		g.drawImage(image, x, y);
	}
	public boolean intersects(Rectangle rect) {
		Rectangle rectbal = new Rectangle(x,y,3,3);
		return rectbal.intersects(rect);
	}
}
