Hello guys,
i have start to programming with Grennfoot and i have a Problem with my command. I would like to make an command that looks if there are buses in radius. When its so the cars should stop (speed ==0).
if (getObjectsInRange(50 /*radius to check*/, Bus.class).isEmpty()) //if there is no bus
{
//do something... move, turn and so on
}public class Car extends Actor
{
private int speed = 1;
public void act()
{
if(isBusInRange())
speed = 0;
else
speed = 1;
}
private boolean isBusInRange(){
return !getObjectsInRange(40, Bus.class).isEmpty(); //finds buses within a 40 pixel radius
}
}public car[]cars= new car[17];
public void act()
{
if (getObjectsInRange(50, Bus.class).isEmpty())
{
move(1);
// you could perform some other actions here (like turning or "atEdge" or non-bus collision checking)
}
}