/* 
	Field.java

	[ more java @ mlab - 10-17.1.2000 - juhuu@katastro.fi ]
*/
import java.awt.*;
import java.util.*;

public class Field
{
	byte[]		yData;
	int			nFieldWidth;
	int			nFieldHeight;
	int			nFieldX;
	int			nFieldY;
	Image[]		imgImages;
	Vector		vTargets;

	int			nTargetAmount;
	int			nImageWidth;	int			nImageHeight;
	
	// Field constructor :	yData		 - the data for the field
	//						nFieldWidth  - the width of the field, measured in targets
	//						nFieldHeight - the height of the field, measured in targets
	//						nFieldX		 - the start x coordinate of the field
	//						nFieldY		 - the start y coordinate of the field
	//						imgImages	 - the set of images to be used
	public Field(byte[] bytes, int f_width, int f_height, int f_x, int f_y, Image[] img)
	{
		yData			= bytes;
		nFieldWidth		= f_width;
		nFieldHeight	= f_height;
		nFieldX			= f_x;
		nFieldY			= f_y;
		imgImages		= img;
		vTargets		= new Vector();

		// all the images have the same size, use the size of the first one		nImageWidth		= imgImages[0].getWidth(null);		nImageHeight	= imgImages[0].getHeight(null);

		byte yIndex;
		for(int i = 0 ; i < nFieldHeight; i++)		{
			for(int j = 0 ; j < nFieldWidth; j++)			{				yIndex = yData[i * nFieldWidth + j];
				if(yIndex != 0)				{					vTargets.addElement(new Target(nFieldX + j * nImageWidth, nFieldY + i * nImageHeight, imgImages[yIndex - 1]));
				}			}
		}

		nTargetAmount = vTargets.size();
	}

	public void draw(Graphics g)
	{
		Target	targetTmp;
		for(int i = 0 ; i < nTargetAmount; i++)		{
			targetTmp = (Target) vTargets.elementAt(i);			targetTmp.draw(g);
		}	}
}
