Last active
August 29, 2015 14:16
-
-
Save CapacitorSet/40d017a5e1fe536333e1 to your computer and use it in GitHub Desktop.
Simulates an element of the system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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