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


class Playfield extends Raster {

  public Raster background;
  Sprite sprite[];
  int num;

  public Playfield()
  {
  }

  public Playfield(Image bgnd, int numSprites)
  {
    super(bgnd);
    background = new Raster(bgnd);
    sprite = new Sprite[numSprites];
    num = numSprites;
  }
    
  public void addSprite(int i, Sprite s)
  {
    sprite[i] = s;
    sprite[i].order = i;
  }
  
  public void Draw()
  {
    int i, j;
    // first draw background
    int w = getWidth();
    int h = getHeight();
    for (j=0; j<h; j++)
      for (i=0; i<w; i++)
	setPixel(background.getPixel(i, j), i, j); 

    // then draw sprites on the background
    for (i=0; i<num; i++)
      sprite[i].Draw(this);
  }

  public void switchSprite(int first, int second)
  {
    sprite[first].order = second;
    sprite[second].order = first;
    Sprite temp = sprite[first];
    sprite[first] = sprite[second];
    sprite[second] = temp;
  }

}
