import java.awt.*;
import java.awt.image.*;

class Sprite extends Raster
{
	
	protected int x,y;
	Color trans;

	
	public Sprite () {};
	
	
  public Sprite (Image image)
  {
  	super(image);
  	trans = Color.white;
  	x = 0; y = 0;
  }

	
	/*public Sprite (Image image, Color back)
	{
		super(image);
		trans = back;
  	x = 0; y = 0;
	};*/
	

	public boolean touch(int a, int b)
	{
		int tempA = a-x;
		if ((tempA>=0)&&(tempA<width))
		{
			int tempB = b-y;
			if ((tempB>=0)&&(tempB<height))
				if (!getColor(tempA,tempB).equals(trans))
					return true;
		}
		return false;
	};
	
	
	public boolean collideWith(Sprite s)
	{
		int midx1 = (x<<1+width)/2;
		int midy1 = (y<<1+height)/2;
		int midx2 = (s.x<<1+s.width)/2;
		int midy2 = (s.y<<1+s.height)/2;
		int dist = Math.abs(midx1-midx2) + Math.abs(midy1-midy2);
		if (dist<(s.width/2 + s.height/2))
			return true;
		return false;
	};
	
	
	public void setXY(int a, int b)
	{
		x = a-width/2; y = b-height/2;
	};
	
	public void setState(String s){};
	
	public boolean draw(Raster background)
	{
		int maxX = background.getWidth();
		int maxY = background.getHeight();
		int Xhi = Math.min(maxX-x,width);
		int Yhi = Math.min(maxY-y,height);
		int Xlo = x<0 ? -x: 0;
		int Ylo = y<0 ? -y: 0;
		Color c;
		for (int i=Xlo; i<Xhi; i++)
			for (int j=Ylo; j<Yhi; j++)
			{
				c = getColor(i,j);
				if (!c.equals(trans))
					background.setColor(c,x+i,y+j);
			};
		return (true);
	};
	
	public boolean clockTick(Sprite magnet)
	{
		int dx = x - magnet.x;
		int dy = y - magnet.y;
		double norm = Math.sqrt(dx*dx+dy*dy);
		dx = (int)(dx*3/norm);
		dy = (int)(dy*3/norm);
		x -= dx;
		y -= dy;
		return false;
	};
	
}