package boxs;

import personnage.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 Box 
{
	Image img;
	public ArrayList <Integer> x;
	public ArrayList <Integer> y;
	
	public Box() throws SlickException
	{
		x = new ArrayList <Integer>();
		y = new ArrayList <Integer>();
	}
	public void spawn(int[][] map)
	{
		int xrand, yrand;
		int i = 0;
		do
		{
			xrand = (int) (Math.random()*23);
			yrand = (int) (Math.random()*19);
		}while((map[yrand][xrand] != 0) || (map[yrand+1][xrand] == 0) && i++ < 420);
		System.out.println("Spawning box in x:"+xrand+" y:"+yrand);
		x.add(xrand*32+(32-img.getWidth())/2);
		y.add(yrand*32+(32-img.getHeight())/2);
			
	}
	public void check(Personnage perso)
	{
		Rectangle perrect = new Rectangle(perso.x, perso.y, 22, 32);
		for(int j=0;j<x.size();j++)
		{
			if(perrect.intersects(new Rectangle(x.get(j), y.get(j), img.getWidth(), img.getHeight())))
			{
				x.remove(j);
				y.remove(j);
				this.action(perso);
			}
		}
	}
	public void action(Personnage perso)
	{
		
	}
	public void draw(Graphics g)
	{
		for(int j=0;j<x.size();j++)
		{
			g.drawImage(img, x.get(j), y.get(j));
		}
	}
}
