Hi guys, im new to Greenfoot and im struggling :(
As title says, I wanna know how can i make object1 move object2 to a certain location for example a 'square' and object 1 goes back to its original potion. I know how I can make it move via keyboard but I wanna make it automatically detect the object and push it to the square and go back to its original position. I was thinking of trying to make a scanner and scan the area for the object but it didnt work out in the end :(
any help would be appreciated,
Here is my robot -
public void act()
{
int x = getX();
int y = getY();
setLocation(x + 1, y);
}
public boolean foundBomb()
{
Actor bomb = getOneObjectAtOffset(0, 0, bomb_1.class);
if(bomb != null) {
return true;
}
else {
return false;
}
}
}
Here is my 'tank'
public void act()
{
if (robotBump())
move();
}
public boolean robotBump()
{
Actor robot = getOneObjectAtOffset(0, 0, robot_1.class);
if(robot != null) {
return true;
}
else {
return false;
}
}
public void move()
{
int x = getX();
int y = getY();
setLocation(x + 1, y);
}
and my square is empty

