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

/* Playfield has a background raster and an array of the sprites
   on the playfield. */


//Playfield Class
//**************************************************************
class Playfield extends Raster
{
  protected Raster background;
  protected Sprite sprite[]; // list of sprites on this playfield
  protected int totalSprites;
  //**************************************************************
 public Playfield(Image bgnd, int numSprites)
       /* This constructor initializes the Playfield
	  to the actual background. And creates a sprite array */
  {
    super(bgnd);
    background = new Raster(bgnd);
    totalSprites = numSprites;
    sprite = new Sprite[totalSprites];
  }
  //**************************************************************
  public void addSprite(int i, Sprite s)
       // add a sprite to the array
  {
    sprite[i] = s;
  }
  //**************************************************************
  public void Draw()
       // Draw the background and all the sprites
  {
    
    int x, y;
    int bgndPix[] = background.getPixels();
    int bgndW = background.getWidth();
    int Pix[] = getPixels();
    int bgndH = background.getHeight();
    for (x=0; x<bgndW; x++)
      for (y=0; y<bgndH; y++)
	{
	  Pix[(y*width)+x] = bgndPix[(y*bgndW)+x];
	}
    for(x=0; x<totalSprites; x++)
      sprite[x].Draw(this);
    
  }

}
  
