Here is my code
import greenfoot.*;
/**
* Write a description of class Ladybug1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bug extends Actor
{
private int beehivesEaten;
/**
* Act - do whatever the Ladybug1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Bug()
{
beehivesEaten = 0;
}
public void act()
{
followBeehive();
lookForBeehive();
}
public void followBeehive()
{
turnTowards(150,500);
Actor beehive = (Actor) getOneIntersectingObject(Beehive.class);
move(3);
if(beehive !=null)
{
getWorld().removeObject(beehive);
}
}
public void attackBeehive()
{
if(!getObjectsInRange(500, Beehive.class).isEmpty())
{
Actor beehive=(Actor) getObjectsInRange(200, Beehive.class).get(0);
if(beehive !=null)
{
followBeehive();
}
}
}
private void lookForBeehive()
{
if ( canSee(Beehive.class) )
{
Greenfoot.playSound("wah.mp3");
eat(Beehive.class);
beehivesEaten = beehivesEaten + 1;
}
}
}
// References