I'm trying to make it so when my forager actor touches my flower actor (which is a parent class to pinkFlower, purpleFlower and yellowFlower) a method in the world class is called. However, it is not working. I also do not know how to call my stop() method from my bee class and how to remove the flower it has touched. I have nothing in my children flower classes except setting the image of them. This is the code i have for it:
in the BeeWorld:
and in the Flower class:
public BeeWorld(int weatherVal)
{
//set background to main screen when button is pressed
super(864, 540, 1);
setBackground(new GreenfootImage("Background.png"));
//add buttons
btnAddDay = new Buttons();
btnAddDay.setImage(new GreenfootImage("addDaybutton.png"));
btnHelp = new Buttons();
btnHelp.setImage(new GreenfootImage("helpButton.png"));
btnEndSimulation = new Buttons();
btnEndSimulation.setImage(new GreenfootImage("EndSimulationbutton.png"));
addObject(btnEndSimulation, 50, 500);
//run new day
newDay();
//add the counter for the bee value
showText("Bees: ", 810, 20);
//declare weatherValue
weatherValue = weatherVal;
//set honey and nectar values
nectarValue = 0;
honeyValue = 0;
showText("Honey: " + honeyValue, 810, 110);
showText("Nectar: " + nectarValue, 810, 80);
public void beeTouchingFlower()
{
//when bee touches flower:
//remove flower
//stop bee moving
//add to nectar value and update nectar counter
updateNectar();
}
public void updateNectar()
{
//add to nectar value
nectarValue = nectarValue + 2;
//add the counter for the nectar value
showText("Nectar: " + nectarValue, 810, 80);
}
public void act()
{
//check if bee is touching flower
beeTouchingFlower();
}
public void beeTouchingFlower()
{
//check if bee is touching flower
Flower f = (Flower) getWorld().getObjects(Flower.class).get(0);
if(f != null && f.touchingForager())
{
//run beeTouchFlower in world class
BeeWorld b = (BeeWorld) getWorld();
b.beeTouchingFlower();
}
}
