Find Closest Food

private Food findClosestFood() { Food closestFood = null; if (fList.size()>0) { closestFood = fList.get(0); float closestDist = PVector.dist(p.getPos(), closestFood.getPos()); for (Food f:fList) if (PVector.dist(p.getPos(), f.getPos()) < closestDist) { closestFood = f; closestDist = PVector.dist(p.getPos(), closestFood.getPos()); } } return closestFood; }
Find the closest food instance on an ArrayList
IAT 265 (Fall 2017)
Lab 05

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.