package project1;

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

class Playfield extends Raster {
  Raster background;          // background image
  AnimatedSprite sprite[];    // list of sprites on this playfield
  int num;                    // the number of sprites on this playfield

public Playfield(Image bgnd, int numSprites){
  super(bgnd);
  background=new Raster(bgnd);
  sprite = new AnimatedSprite[numSprites];
  num = numSprites;
}

public void addSprite(int i, AnimatedSprite s){
  //i will be the index for which sprite we are adding
  //if you try to add a Sprite with an int i which is greater than the 
  //the highest index allocated when the playfield was constructed, the
  //method will return without adding the sprite.
  if (i < num) {
    sprite[i]=s;
  } 
}

public void Draw() {
  //will combine the background with all of the animated sprites and draw.
  System.arraycopy(background.getPixels(), 0, this.pixel, 0, background.size());
  for (int i=0; i<num; i++) {
    AnimatedSprite as = sprite[i];
    as.Draw(this);
  }
  
}

}
