Skip to content

Instantly share code, notes, and snippets.

@CapacitorSet
Last active August 29, 2015 14:16
Show Gist options
  • Save CapacitorSet/40d017a5e1fe536333e1 to your computer and use it in GitHub Desktop.
Save CapacitorSet/40d017a5e1fe536333e1 to your computer and use it in GitHub Desktop.
Simulates an element of the system
public class Element {
public mortality;
public boolean alive;
public int age;
public Point position;
public void tick() {
updateMortality();
if (alive) {
age++;
if (random(0,1)<mortality) {
alive = false;
return;
}
}
}
public Vector escape(Point enemies[]) {
Vector route = new Vector();
for (Point enemy:enemies) {
route.add(new Vector(this.position, enemy));
}
route.invert();
return route;
}
void updateMortality() {
// dMortality/dt = age * 0.00001
mortality += age*0.00001;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment