[Home]Hanji/GravPoint

Robo Home | Hanji | Changes | Preferences | AllPages

GravPoint? is the class that represents an attracting or repelling point for /AGravEngine:
 package neh;

 /**A simple class describing a point of gravity*/
 public class GravPoint {
	/**The x coordinate of the point*/
	public double x;
	/**The y coordinate of the point*/
	public double y;
	/**The attractiveness of the point(negative will repel)*/
	public double strength;
	/**The time at which the point was created*/
	public long ctime;
	/**The point's lifetime (a lifetime of 0 never dies)*/
	public long life;
	
	/**Default constructor initializes all memebers to 0*/
	public GravPoint() {
		this(0,0,0,0,0);
	}
	
	/**
	 * Constructs a GravPoint with the specified position,
	 * strength, and infinite life.
	 */
	public GravPoint(double x, double y, double strength) {
		this(x,y,strength,0,0);
	}
	
	/**Constructs a GravPoint with the specified attributes*/
	public GravPoint(double x, double y, double strength, long ctime,
							long life) {
		this.x = x;
		this.y = y;
		this.strength = strength;
		this.ctime = ctime;
		this.life = life;
	}
	
	/**
	 * Update the point. Returns true if the point needs to be killed.
	 * For GravPoint this merely checks if our lifetime has been
	 * exceeded, but, since this is called before calculations are
	 * made using the point, it could be used to adjust position and
	 * strength in subclasses.
	 *
	 * @param time The current game time
	 * @returns true if the point needs to be killed, false otherwise
	 */
	 public boolean update(long time) {
	 	return ((life != 0) && (ctime + life) < time);
	 }
	 	
 }

GravPoint? is designed to be customizable. I have made subclasses that do things like randomly vary strength, or move with a given velocity, or activate after a given delay, and pretty much anything you can think of should be doable.
Questions or comments:

Robo Home | Hanji | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited April 5, 2003 11:02 EST by PEZ (diff)
Search: