// Annamaria Cherubin: last edited on 9-27-1998
// 6.837 - Project #1
// Playfield.java

package proj1;
import java.awt.*;
import java.awt.image.*;

public class Playfield extends Raster {
  Raster background;                    // background image
  AnimatedSprite sprite[];              // list of sprites on this playfield

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

  // Methods
  public void addSprite(int i, AnimatedSprite s) {
    // effects: add Sprite s to this Playfield.
    if (i < sprite.length)
      sprite[i] = s;
  }

  public void Draw() {
    // effects: uses the draw method from AnimatedSprite to draw all the sprites
    //          onto the background.
    System.arraycopy(background.getPixels(), 0, this.pixel, 0, background.size());
    AnimatedSprite s;
    for (int i = 0; i < sprite.length; i++) {
      s = sprite[i];
      s.Draw(this);
    }
  }

} // end class Playfield
