This site requires JavaScript, please enable it in your browser!
Greenfoot back
Blackskater
Blackskater wrote ...

2015/8/10

I want my wombat to surround rocks when he calculates the distance in this method. How can I do that?

Blackskater Blackskater

2015/8/10

#
public Actor findClosestActor(Class c) { List<Actor> list= getWorld().getObjects(c); Actor closest=null; int minDistance=1000; for(int i=0; i<list.size(); i++) { Actor actor=list.get(i); int dist=calcDistanceTo(actor); if(closest==null || dist<minDistance) { closest=actor; minDistance=dist; } } return closest; }
danpost danpost

2015/8/10

#
Are you using a gridded world? (what is the cellsize of your world) My intuition says it might be '1'; but, I would like verification on that to be sure. How can one object (a wombat) surround multiple objects (rocks)? I would presume that your wombat is using the given method to find the closest Rock object to itself. Please explain how the information (what rock is closest) will be used in how the wombat should behave.
You need to login to post a reply.