can any one help me, how would you track another object(class)
or can some one please show me a scenorio that does this.
import greenfoot.*;
import java.util.List;
public class Tracker extends Actor
{
Actor target = null;
public void act()
{
// no target aquired, wait for one
if ( target == null )
{
// Look for targets
List<Actor> targets = getObjectsInRange(100, Actor.class);
if ( !targets.isEmpty() )
{
// If possible targets seen, choose one at random.
int choice = Greenfoot.getRandomNumber(targets.size() );
target = targets.get(choice);
}
}
//target acquired. Seek!
else
{
// Close 90% of distance to target. See Achilles/Tortoise.. ;)
setLocation( getX() + (target.getX()-getX())/10 , getY() + (target.getY()-getY())/10 );
}
}
}