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

class Playfield extends Raster {
  Raster background;   // background image
  Sprite sprite[];     // list of sprites on this playfield
  /* CHECK on casting; array of superclass?!? */
  
  public Playfield(Image bgnd, int numSprites)
  {
    super(bgnd);
    background = new Raster(bgnd);
    sprite = new Sprite[numSprites];
  }

  public void addSprite(int i, Sprite s)
  {
    sprite[i] = s;
  }

  public void changeSprite(int i, Sprite s)  /* currently not used */
  {
    sprite[i] = s;
  }


  public void Draw( )
  {
    for (int y=0; y < background.height; y++)             // Draw the background,
      for (int x=0; x < background.width; x++)
	{//System.out.println("x:  " + x + "    y:  " + y);
	this.setPixel(background.getPixel(x,y),x,y);
	}

    for (int i=0; i < sprite.length; i++)     // then draw each sprite on top.
      sprite[i].Draw(this);
      /*  Note: sprite[i] will always be "underneath" sprite[j] for all i < j.  */
  } // end Draw method


  public boolean IsSpriteHit(int Xclick, int Yclick)
  {
    for (int i=0; i < sprite.length; i++)     // check if each sprite was hit.
      if (sprite[i].clickedOn(Xclick, Yclick, background))
       return(true);
    return(false);
  }

} // end Playfield class


/* ---------
        class Playfield extends Raster {
             Raster background;          // background image
             AnimatedSprite sprite[];    // list of sprites on this playfield
         
             public Playfield(Image bgnd, int numSprites);
             public void addSprite(int i, AnimatedSprite s);
             public void Draw( );
         }
-------- */
