i working on expanding sketch: http://www.openprocessing.org/sketch/11045
trying add aging boids agents using framecount. initialise arraylist age inbuilt:
boids = new arraylist(); (int = 0; < boidnum; i++) { agent boid = new agent(random(width), random(height), 1, round(framecount + random(300, 400))); boids.add(boid); }
then retrieve :
agent(float posx, float posy, int t, int a) { mass = 5.0; location = new pvector(posx, posy); vel = new pvector(random(-5,5), random(-5, 5)); acc = new pvector(); type = t; wdelta = 0.0; action = 0; age = a; }
i want use living cycle :
if (framecount != age) { age = age - 1; } if (framecount == age) { boids.remove(this); }
but i'm not sure in code should put it. best way it, or overcomplicating things?
update: wrote new method:
void boid(arraylist boids) { (int = 0; < boids.size(); i++) { if (framecount >= age) { boids.remove(this); } } }
which being called from:
void steer(arraylist boids, arraylist predators, arraylist landscape) { if (type == 1) boid(boids); ...
it sounds want put code in agent
class, after updating , drawing of agent
- taking quick @ code, that's run()
function in agent
class.
but i'm not totally sure why you're comparing each agent
's age framecount
. framecount
variable tells how long sketch has been running. if statement kills birds have same age sketch, doesn't make sense.
instead, need have 2 variables in agent
class: age
variable starts @ 0
, increments 1 each frame, , maxage
variable stores age @ agent
should removed.
if want friendly advice though, i'd recommend starting on scratch own code instead of trying modify existing one, if aren't sure how code works yet. might seem you're saving time using existing code, if don't know how code works yet, you'll save bunch of headaches writing yourself. though.
Comments
Post a Comment