In Class Exercise
package agentSystem;
import igeo.IVec;
import igeo.IPoint;
public class MowingAgent extends Agent {
float vel = 25;
double mowerwidth = 25;
double desiredoverlap = 0.25;
IVec baseDir;
IVec currDir;
boolean done = false;
int time = 0;
IPoint pt;
IVec newPos;
double turn = 1.57;
public MowingAgent(AgentManager _p5, IVec _pos, IVec _bdir) {
super(_p5,_pos);
this.pt = new IPoint(this.pos);
this.newPos = new IVec(this.pos);
this.baseDir = _bdir;
}
public void mow() {
//determine which direction I need to be going
if(!this.inBounds())
{
//change direction
baseDir.neg();
//turn opposite each time
this.turn = -this.turn;
//turn around and shift down to get the desired mower overlap
this.newPos = this.pos.dup().add(this.currDir.dup().rot(this.turn).len(mowerwidth-(mowerwidth*desiredoverlap)));
this.pos.set(this.newPos);
//get back into the lawn
this.pos.set(this.pos.dup().add(this.currDir.dup().len(vel)));
}
//determine how far Im mowing
this.newPos.set(this.pos.dup().add(this.currDir.dup().len(vel)));
//mow
this.pos.set(this.newPos);
}
public boolean inBounds() {
return this.p5.boundaryCrv.isInside2d(this.pos);
}
public void update() {
if(!done) {
mow();
} else {
System.out.println("whew, time for a beer");
}
}
public void redraw() {
pt.pos = this.pos;
}
}