import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;

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


  //constructor
  public Sprite()
  {
  }

  //constructor
  public Sprite(int width, int height)
  {
    super(width, height);
  }

  //constructor
  public Sprite(Image image)
  {
    super(image);  
    x = 100;
    y = 100;
  }

  //render sprite onto Raster bgnd, clipping and applying transparency.
  public void Draw(Raster bgnd)
  {
    int x1 = x;
    int y1 = y;
    int x2 = x + this.width;
    int y2 = y + this.height;
   
    //clipping
    if (x2 > bgnd.width)
      x2 = bgnd.width;
    if (y2 > bgnd.height)
      y2 = bgnd.height;
    if (x1 < 0) 
      x = 0;
    if (y1 < 0)
      y = 0;

    //assign pixels, making no change if pixels are transparent.
    for (int i = x; i < (x2); i++)
      {
	for (int j = y; j < (y2); j++)
	  {
	    int pix = this.getPixel(i-x1,j-y1);
	    if (pix < 8388607)
	      bgnd.setPixel(pix,i,j);
	  }
      }
  }
}
