import java.awt.*;
import java.util.*;

public class Playfield extends Raster implements Cloneable
{
	public Raster background;	// the permanent copy of the background image
//	public AnimatedSprite[] sprites;			// array of sprites to go on the field
	public Vector sprites;

	public Playfield(Image bgnd)
	{
		super(bgnd);
		background = new Raster(bgnd);
//		sprites = new AnimatedSprite[0];
		sprites = new Vector(10);
	}
	
	public Playfield()
	{
	}
	
	public Playfield getclone()
	{
		try
		{
			return (Playfield)this.clone();
		}
		catch (CloneNotSupportedException e)
		{
			return null;
		}
	}
	
	public void addSprite(AnimatedSprite s)
	{
		sprites.addElement(s);
	}
	
	public void deleteSprite(int num)
	{
		sprites.removeElementAt(num);
	}
	
	public void deleteSprite(AnimatedSprite s)
	{
		if (sprites.contains(s))
			sprites.removeElement(s);
	}
	
	public Raster pixelowner(int x, int y)
	{
		for (int i=sprites.size()-1; i>=0; i--)
		{
			if (((AnimatedSprite)sprites.elementAt(i)).ownspixel(x, y))
			{
				return ((Raster)sprites.elementAt(i));
			}
		}
		return this;
	}			
	
	public void Draw()
	{
	  //		pixel=(int[])background.pixel.clone();
	  
	  System.arraycopy(background.pixel, 0, pixel, 0, background.pixel.length);
		for (int i=0; i<sprites.size(); i++)
		{
			((AnimatedSprite)sprites.elementAt(i)).tick(this);
		}
	}
}
