import java.awt.*;
import java.awt.image.*;

class Sprite extends Raster {
        int x,y;             // current position of sprite on playfield
        int fwidth,fheight;  // size of a sprite's frame
        
        public Sprite(int width, int height)   // initialize sprite with an image
        {   
            super(width,height);
            x=0;
            y=0;
            fwidth=width;
            fheight=height;
        } 
        
        public Sprite(Image image)   // initialize sprite with an image
        {   
            super(image);
            x=0;
            y=0;
            fwidth=width;
            fheight=height;
        } 
        public void Draw(Raster bgnd) // draws sprite on a Raster
        { 
           int i, j; 
           int bgndx=x-1; //coordinates on the Raster
           int bgndy=y-1;
           int bgndwidth=bgnd.getWidth();
           int bgndheight=bgnd.getHeight();
           for (j=0; j<fheight; j++)
            {   
              bgndy++;  
              for (i=0; i<fwidth; i++)  
                  {   
                      int pixelvalue=pixel[j*fwidth+i];
                      bgndx++;
                      //Check to see if pixel is on screen and not transparent
                      if (((bgndy>=0)&&(bgndx>=0))&&((bgndx<bgndwidth)&&(bgndy<bgndheight)) 
                            && (0<(24<<pixelvalue))){
                        bgnd.setPixel(pixelvalue,bgndx,bgndy);};  
                  }
              bgndx-=fwidth;
            }
        }
        /* 
        Set the location of the sprite on the Raster screen
        */
        public void set_location(int x, int y)
        {
              this.x=x;
              this.y=y;
        }
        /*
        Check to see if a pixel on the screen belongs to the sprite 
        and is transparent or not
        */
        public boolean transparent(int screenx, int screeny)
        {
            //check to see if the pixel if a sprite pixel
             if (((screenx>=x)&&(screenx<=(x+width)))&&
                ((screeny>=y)&&(screeny<=(y+width))))
                //if it is then return the sprite pixel
               return ((0<(24<<pixel[(screeny-y)*width+(screenx-x)])));
               return false;
        }
        
        }
               
 