/*
	WorldPanel....class defining the canvas in which the players live
*/

import java.awt.*;
import javax.swing.*;
import java.awt.image.BufferedImage;

public class WorldPanel extends JPanel {
	WorldFrame theFrame;
	static BufferedImage theImage;
	static Graphics thePalate;
	static int width,height;
	double scale;
	double scaleInc = 0.1;
	double [] offset = {0,0};
	
	public WorldPanel (int width, int height, WorldFrame theFrame) {
		this.width = width;
		this.height = height;
		scale = width/Sim2D.xDimension;
		this.theFrame = theFrame;
		setSize(width,height);
		
	}
	public void initialize() {
		theImage = (BufferedImage)createImage(width,height);
		thePalate = theImage.getGraphics();
	}
	
	public void drawAllThings () {
		for (int i=0;i<Thing.thingCt;i++) {
			Thing.theThings[i].drawYourself(thePalate,scale,offset);
		}
	}
	
	public static void drawInfoString (String info) {
		thePalate.setColor(Color.white);
		thePalate.drawString(info,10,20);
	}
	
	public static void clearInfoArea () {
		thePalate.setColor(Color.black);
		thePalate.fillRect(10,10,width-20,30);
	}
	
	public void drawBoxAroundWorld () {
		thePalate.setColor(Color.white);
		int xCen = (int)(-offset[0]*scale);
		int yCen = (int)(-offset[1]*scale);
		int worldWidth = (int) (Sim2D.xDimension*scale);
		int worldHeight = (int) (Sim2D.yDimension*scale);
		thePalate.drawRect(xCen,yCen,worldWidth-1,worldHeight-1);
	}
	
	public void update(Graphics g) {
		paint(g);
	}
	
	public void paint (Graphics g) {
		g.drawImage(theImage,0,0,null);
	}
	
	
	public void clearImage() {
		thePalate.setColor(Color.black);
		thePalate.fillRect(0,0,width,height);
	}

}

