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


class Sprite extends Raster {
  int x, y;           // current position of sprite on playfield

  // initialize sprite with an image
  public Sprite(Image image){         
    super(image);
    x = 0;
    y = 0;
  }      
	
  // draws sprite on a Raster     
  public void Draw(Raster bgnd){            
    int width = getWidth();
    int height = getHeight();
    for (int i = 0; i < width; i++)
      for (int j = 0; j < height; j++)
        // clipping 
        if (((x+i) < bgnd.getWidth()) &&
            ((x+i) >= 0) && ((y+j) >= 0) && ((y+j) < bgnd.getHeight()))
	    // replace correct playfield pixels with sprite pixels
            if ((pixel[j*width+i]) < 0)
              bgnd.setPixel(this.getPixel(i,j), this.x+i, y+j);
  }
  
  // draws sprite on a Raster
  public int inSprite(Raster bgnd, int x, int y){            
    int found = -1;
    int width = getWidth();
    int height = getHeight();
    // check to see if coords. x, y within footprint of sprite
    if ((x >= this.x) && (x < this.x+width) && (y >= this.y) && (y < this.y + height))
        if (this.pixel[(y-this.y)*width+x-this.x] < 0)
          found = 1;
    return found;   
  }
}






