Hello,
I have a dog actor which eats the bone if he touches the bone.
But I also have a dogwithglasses Actor which needs to move to the Bone if he sees it and then eat it if he touches it.
Both actors move randomly and the Bone is randomly placed in the world.
Ofcourse the dog with glasses needs to be able to see the bone from further away therefore I need to use the getObjectsInRange() method.
But if the Bone is in range how do I get the location of the bone to use in the dogwithglasses actor?
I need the location, so if the dogwithglasses can "see" the bone with getObjectsInRange I can use setLocation() to move the dog to the bone so he can eat the bone.
How would you do this?
dogwithglasses:
Obviously "Bone location isn't valid code"
Thanks
-Kelvin
public class Dogwithglasses extends Animal
{
private int dSteps = 0;
public void act()
{
move(5);
dSteps++;
life();
}
public void life()
{
if(Greenfoot.getRandomNumber(100) > 90){
turn(Greenfoot.getRandomNumber(90) - 45);
}
bark();
}
public void glasses()
{
if (getObjectsInRange(50, Bone.class))
{
setLocation(Bone Location);
}
}
}

