 import java.applet.*;
 import java.awt.*;
 import java.awt.image.*;
 import Raster;

     class Sprite extends Raster
    {
             int x, y;           // current position of sprite on playfield
             int width, height;  // size of a sprite's frame
	     Raster r1, r_output;
             


             public Sprite(Image img)          // initialize sprite with an image
	       {
	        r1 = new Raster(img);
		width=r1.getWidth();
		height=r1.getHeight();
                x=0;
		y=0;
	       }



             public void Draw(Raster bgnd)              // draws sprite on a Raster
	      {
	        int pix; // pix stores pixel value tempararily
                Color c;  // c stores color for a pixel  tempararily
                r_output = new Raster();


		/* put background into raster r_output first */

                for(int i=0; i<=bgnd.width; i++)
		  { for(int j=0; j<=bgnd.height; j++)
		    { pix=bgnd.getPixel(i,j);
		      c=bgnd.getColor(i,j);
		      r_output.setPixel(pix, i, j);
		      r_output.setColor(c, i, j);
		    }
		  }
                

		/* then put the  sprite into raster r_output in addition to the background */

		for(int i=0; i<=width; i++)
		  { for(int j=0; j<=height; j++)
		    {
		      pix=r1.getPixel(i,j);
		      c=r1.getColor(i,j);
		      //                      if(((boolean)pix>>24)&0xFF)         //if the pixel is transparent
			{ if((x+i) < bgnd.width && (y+j) < bgnd.height)  //and if pixels are within frame of bgnd
		          r_output.setPixel(pix, x+i, y+j);
			  r_output.setColor(c, x+i, y+j);
			}
		    }  
		  }
	       
	       }
    
     }
         



