import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import Raster;

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

   public Sprite() {}                        //  for compatability

   public Sprite( Image image, int x, int y)
   {
      super( image);
      this.x = x;  this.y = y;
   }

   public Sprite( Image image)
   {
      this( image, 0, 0);
   }

/*   public Sprite( String imageName)
   {
      this( getImage( getDocumentBase(), imageName));
   }
*/

   public void Draw( Raster bg, int x, int y, int x_top_pixels)
   {
      this.x = x;  this.y = y;

      if (x_top_pixels > super.getHeight())
         System.out.println( "Error:  x_top_pixels too large; super.getHeight() is " +
			super.getHeight());

      int maxX, maxY, minX;
      maxX = (super.getWidth()+x   >  bg.getWidth())   ?  bg.getWidth()-x   :  super.getWidth();
      maxY = (x_top_pixels+y       >  bg.getHeight())  ?  bg.getHeight()-y  :  x_top_pixels;
      minX = (x < 0  ?  -x  : 0);
         
      for (int i = minX; i < maxX; i++)
         for (int j = 0; j < maxY; j++)
         {
            int p = super.getPixel( i, j);
            if ((p & 0xFF000000)  !=  0)
               bg.setPixel( super.getPixel(i,j), i+x, j+y);
         }
   }

   public void Draw( Raster bg, int x, int y) { this.Draw( bg, x, y, super.getHeight()); }

   public void Draw( Raster bg)               { this.Draw( bg, x, y, super.getHeight()); }
}
