@Override
protected void traceBestFood(ArrayList<Food> fList) {
if (fList.size()>0) {
// set the 1st item as default target
Food target = fList.get(0);
float targetAttraction = this.getAttraction(target);
// find the closer one
for (Food f:fList) if (this.getAttraction(f) > targetAttraction) {
target = f;
targetAttraction = this.getAttraction(target);
}
// make animal follow this target
this.attractedBy(target);
}
}
protected float getAttraction(Food f) {
return f.getSize()*10/PVector.dist(pos, f.getPos());
}
Additional code for SmartPacwoman class
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.