I am making a snake game on Greenfoot but with two types of food: blueberries and cherries. Cherries add only 5 points while blueberries add 10.
I am trying to add a blueberry in the world for every 5 cherries eaten, but I am not sure how to implement that in Greenfoot. I have different classes for Blueberries and Cherries.
This is the code in the eatFood method in the Snake head class:
Any help would be appreciated!
public void eatFood(){
if(isTouching(Cherries.class)){
removeTouching(Cherries.class);
cherriesEaten++;
MyWorld world = (MyWorld)getWorld();
Score score = world.getScore();
score.addScore();
if (cherriesEaten > 5){
world.addBlueberries();
}
else{
world.addCherries();
}
}
if (isTouching(Blueberries.class)){
removeTouching(Blueberries.class);
blueberriesEaten++;
MyWorld world = (MyWorld)getWorld();
world.addBlueberries();
}
}
