package project1;

import java.awt.*;
import java.awt.image.*;

class Sprite extends Raster {
  int x, y;           // current position of sprite on playfield
  int width, height;  // size of a sprite's frame
  
public Sprite(Image image){         // initialize sprite with an image
  super(image);
  x=0;
  y=0;
  width=super.getWidth();
  height=super.getHeight();
}
  
public void Draw(Raster bgnd) {     // draws sprite on a Raster
  //Draw pixels onto the background
  int xbound = bgnd.getWidth();
  int ybound = bgnd.getHeight();
  int xedge = x + width;
  int yedge = y + width;
  if (xedge<xbound)
    xbound=xedge;
  if (yedge<ybound)
    ybound=yedge;
  for (int i=x ; i <= xbound; i++) {
    for (int j=y ; j<= ybound; j++) {
      int pix= this.getPixel(i-x,j-y);
      //Need if statement to test if the pixel is transparent
      //if it is transparent, i won't set the bgnd pixel
      if ((pix >>> 24) != 0)
	bgnd.setPixel(pix,i,j);
    }
  }
}
  
  
}
