import java.awt.*;
import java.awt.image.*;

class Sprite extends Raster {
    int x, y;           // current position of sprite on playfield
    // I don't understand why we don't just use these from the
    //   super class...?
    //int width, height;  // size of a sprite's frame	
    int transparent_color;
    
    public Sprite() {
    }
    
    public Sprite(Image image) {		// initialize sprite with an image
    	super(image);
    	x=0;
    	y=0;
    	transparent_color=this.pixel[0];
    }
    
    public boolean onSprite(int xclick, int yclick) {
		// If the click missed the entire raster, return false...
		if (xclick < x || xclick > x+width || yclick < y || yclick > y+height) {
			return false;
		}
		// Otherwise, see if the click hit a non-transparent pixel...
    	if (this.getPixel(xclick-x,yclick-y) != transparent_color) {
    		return true;
    	}
    	else return false;
    }
    
    public void positionSprite(int xstart, int ystart) {
    	x = xstart;
    	y = ystart;
    }
    
    public void Draw(Raster bgnd) {		// draws sprite on a Raster
    	for (int ystep = 0; ystep<height; ystep++) {
    		for (int xstep=0; xstep<width; xstep++) {
    		    if (this.getPixel(xstep,ystep) != transparent_color) {
    				bgnd.setPixel(this.getPixel(xstep,ystep),x+xstep,y+ystep);
    			}
    		}
    	}
    }
   
}
