import java.awt.*;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;

public class Player
{

    int x;
    int y;
    int frame;
    Image bitmaps[];
    WW_Infinite game;
    int loop[];
    int loopcount;
    int loopsize;

    public Player(Image image, int ai[], WW_Infinite wickywoo, MediaTracker mediatracker)
    {
        bitmaps = null;
        game = null;
        loop = null;
        loopcount = 0;
        loopsize = 0;
        int i = 0;
        game = wickywoo;
        frame = x = y = 0;
        bitmaps = new Image[ai.length / 2];
        for(int j = 0; j < ai.length; j += 2)
        {
            CropImageFilter cropimagefilter = new CropImageFilter(ai[j], ai[j + 1], 30, 30);
            bitmaps[i] = wickywoo.createImage(new FilteredImageSource(image.getSource(), cropimagefilter));
            mediatracker.addImage(bitmaps[i], 0);
            i++;
        }

    }

    public void setFrame(int i)
    {
        frame = i;
    }

    public void setXY(int i, int j)
    {
        x = i;
        y = j;
    }

    public void display(Graphics g)
    {
        g.drawImage(bitmaps[frame], x, y + 2, game);
    }

    boolean collision(int i, int j, int k, int l)
    {
        if(x >= i && x <= i + k && y >= j && y <= j + l)
        {
            return true;
        }
        if(x + 24 >= i && x + 24 <= i + k && y >= j && y <= j + l)
        {
            return true;
        }
        if(x >= i && x <= i + k && y + 24 >= j && y + 24 <= j + l)
        {
            return true;
        }
        if(x + 24 >= i && x + 24 < i + k && y + 24 >= j && y + 24 <= j + l)
        {
            return true;
        }
        if(i >= x && i <= x + 24 && j >= y && j <= y + 24)
        {
            return true;
        }
        if(i >= x && i <= x + 24 && j + l >= y && j + l <= y + 24)
        {
            return true;
        }
        if(i + k >= x && i + k <= x + 24 && j >= y && j <= y + 24)
        {
            return true;
        }
        return i + k >= x && i + k <= x + 24 && j + l >= y && j + l <= y + 24;
    }
}
