/*
	// Thing.... the superclass for all moving objects in this demonstration
*/

import java.awt.*;

public class Thing extends Object {
	static Thing [] theThings = new Thing [100000];		// array of all things
	static int thingCt = 0;									// how many things
	int myThingNumber;					// identifies where in "theThings" this Thing is
	boolean removeMe = false;				// if true this Thing will be eliminated
	double [] coord = new double [2];		// the x and y position of the Thing
	static double maxX = Sim2D.xDimension;	// maximum x position this Thing can occupy
	static double maxY = Sim2D.yDimension;	// maximum y position this Thing can occupy
	static double deltaT = Sim2D.deltaT;
	
	
	public Thing (double initX, double initY) {
		coord[0] = initX;
		coord[1] = initY;
		addThing(this);
	}
	
	public void step () {
		// put the code here to move this object each time-step
	}
	
	public void drawYourself (Graphics g, double scale, double [] offset) {
		// put the code here to draw the object on "g"
	}
	
	
	public static void addThing (Thing newThing) {
		newThing.myThingNumber = thingCt;
		theThings[thingCt] = newThing;
		thingCt++;
	}
	
	public void removeMe () {
		int swapId = myThingNumber;
		theThings[swapId] = theThings[thingCt-1];
		theThings[swapId].myThingNumber = swapId;
		thingCt --;
	}
	
	public static void removeDeadThings () {
		for (int i=0;i<thingCt;i++) {
			if (theThings[i] != null) {
				if (theThings[i].removeMe) { theThings[i].removeMe(); }
			}
		}
	}
	
}

