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

/**
 * A Playfield is a Raster which contains a background
 * image and a number of sprites, which eventually will
 * be animatable.
 *
 */
class Playfield extends Raster
{
	Raster background;
	Sprite sprites[];
	int numSprites;
	
	/// Constructors ///
	
	/**
	 * The Empty Constructor
	 *
	 */
	public Playfield( )
	{
	}
	
	/**
	 * Constructs a Playfield with background img and space for
	 * numSpr sprites
	 */
	public Playfield(Image bg, int numSpr)
	{
		super(bg);	// initialize superclass
		background=new Raster(bg);		// then set up the background

		numSprites=numSpr;
		sprites=new Sprite[numSprites];
	}
	
	/**
	 * Adds a sprite in slot i < numSprites
	 *
	 */
	public boolean addSprite(int i, Sprite spr)
	{
		if(i>=numSprites) return false; // error: overshot array
		
		sprites[i]=spr;
		return true;	// success
	}
	
	/// Other Methods ///
	/**
	 * Renders the background and then the objects into the image buffer
	 *
	 */
	public void draw( )
	{
		for(int i=0;i<width;i++)	// recover the background
			for(int j=0;j<height;j++)
				pixel[width*j+i]=background.getPixel(i,j);

		for(int i=0;i<numSprites;i++)
			sprites[i].draw(this);	// draw the sprites in
	}
}

