I am creating a game where a villain chases a hero. When the hero gets the camoflauge power up, it will turn into the same image as the background. What I am having trouble with is making the villain stop chasing the hero when the hero is camoflauged. My follow method works and my wander method works, the problem is getting the villain to switch from one to the other. Any suggestions?
public class villain extends Actor
{
GreenfootImage camoHero = new GreenfootImage("space.jpg");
hero smile = new hero();
/**
* Act - do whatever the villain wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(getImage() != camoHero)
{
follow();
move(2);}
else
{
wander();
move(2);
}
}
public void follow()
{
String target;
List <hero> group = getObjectsInRange(1000,hero.class);
if(group.size()>0)
{
Actor guy = group.get(0);
int targetX = guy.getX();
int targetY = guy.getY();
turnTowards(targetX, targetY);
}
}
public void wander()
{
if(Greenfoot.getRandomNumber(100) < 10)
{
turn(Greenfoot.getRandomNumber(90)-45);
}
if(getX() <= 5 || getX() >= getWorld().getWidth() - 5)
{
turn(180);
}
if(getY() <= 5 || getY() >= getWorld().getHeight() - 5)
{
turn(180);
}
}
}
