I removed everything that dealt with the worm power-up from the Crab class and altered the following method in that class:
And added this act method to the world class:
Worked beautifully.
public void ifCanSeeWP()
{
if (getOneObjectAtOffset(0, 0, WormPower.class) != null)
{
getWorld().removeObjects(getWorld().getObjects(WormPower.class));
Worm.startPowerUp();
}
}[code]
Then, I re-wrote the Worm class to the following:
[code]import greenfoot.*;
public class Worm extends Animal
{
private static int puTimer;
public void act()
{
if (!isPoweredUp()) return;
Crab crab = (Crab)getWorld().getObjects(Crab.class).get(0);
if (crab == null) return;
turnTowards(crab.getX(), crab.getY());
move(3);
setRotation(0);
}
public static void startPowerUp()
{
puTimer = 200;
}
public static boolean isPoweredUp()
{
return puTimer > 0;
}
public static void checkPuTimer()
{
if (puTimer > 0) puTimer--;
}
}public void act()
{
Worm.checkPuTimer();
}

