I tried to make the actor Alien move and when he encounters any planets, a panel appears with questions. The problem occurs during the collision, the alien must stop when he touches the planet and he mustn't move until he chooses the right answer displayed on the panel (which appears each time the actor touches a planet). When the right answer is chosen, the panel disappears. In my situation the alien keeps moving across the screen.
import greenfoot.*;
public class Alien extends Actor
{
boolean sw_Mercur = false;
boolean sw_Venus = false;
public void act()
{
/*
* If the alien isn't touching any planet, it moves.
*/
if (isTouching(Mercur.class) == false) move(5);
else if (isTouching(Venus.class) == false) move(5);
/*
* If the alien touches an already visited planet, he can continue moving.
*/
if (isTouching(Mercur.class) == true && sw_Mercur == true) move(5);
else if (isTouching(Venus.class) == true && sw_Venus == true) move(5);
if (getWorld().getObjects(Menu.class).isEmpty() == true)
{
if (isTouching(Mercur.class) == true && sw_Mercur == false)
{
getWorld().addObject(new Menu(this, "Mercur"), 1350, 160); // the panel appears only once with question 1
sw_Mercur = true;
if (Greenfoot.isKeyDown("1")) // the answer is correct
{
getWorld().removeObjects(getWorld().getObjects(Menu.class)); // remove menu
move(5); // and let the alien move again
}
}
if (isTouching(Venus.class) == true && sw_Venus == false)
{
getWorld().addObject(new Menu(this, "Venus"), 1350, 160); // the panel appears only once with question 2
sw_Venus = true;
if (Greenfoot.isKeyDown("3")) // the answer is correct
{
getWorld().removeObjects(getWorld().getObjects(Menu.class)); // remove menu
move(5); // and let the alien move again
}
}
}
}
}

