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

/** Playfield.class
 *
 * This class also extends raster, and is the playfield class.  A playfield is
 *  basically a background and all the sprites that are contained within the
 *  background.
 */
public class Playfield extends Raster {
  Raster background;     // Background image
  Sprite sprites[];     // List of sprites contained in the playfield

  /* Constructors */

  /* This constructor allows for future extension
   */
  public Playfield() {
  }
  
  /* This constructor takes a background image and the number of sprites that
   *  will be contained in the playfield
   */
  public Playfield(Image bg, int num_sprites) {
    super(bg);
    background = new Raster(bg);
    sprites = new Sprite[num_sprites];
  }

  /* Methods */

  /* This method adds sprites to the playfield at the specified place in the
   *  array.  This is important because the array determines precedence.  Since
   *  the sprites are drawn in ascending array order, the higher sprites in the
   *  array are drawn on top of the lower sprites on the array.  This is an
   *  easy means for determining which sprites are in front of other sprites.
   */
  public void add_sprite(int i, Sprite s) {
    sprites[i] = s;
  }

  /* This method changes the location of a sprite on the playfield by taking in
   *  an index of which sprite is moving and then changing the sprite's
   *  location to the given coordinates
   */
  public void change_sprite_loc(int num_sprite, int x, int y) {
    sprites[num_sprite].change_loc(x, y);
  }
  
  /* This method draws the playfield by first drawing the background, and then
   *  drawing (in the order of the array) each of the sprites.  When we draw
   *  the playfield, in effect we are building an image up from the background
   *  and the sprites.  This image is stored in the pixel array, which can
   *  later be turned into an Image by standard Raster methods.
   */
  public void Draw() {
    int i, j;
    Image temp;
    
    /* First we copy the background onto the image that we are producing.
     */
    System.arraycopy(background.getPixels(), 0, pixel, 0, pixel.length);

    /* Next, loop through and draw the sprites
     */
    for(i = 0; i < sprites.length; i++)
      sprites[i].Draw(this);
  }
}

