I'm creating a snake game where there are a variety of healthy food to score points from eating. I want the image of the food the change once the food is touched by the snake. Here's my code currently and it's not doing the work. Can somebody help, please?
import greenfoot.*;
public class healthy extends Actor
{
private GreenfootImage image1;
private GreenfootImage image2;
private GreenfootImage image3;
static int score = 10;
static int time;
public healthy()
{
image1 = new GreenfootImage ("fish.png");
image2 = new GreenfootImage ("broccoli.png");
image3 = new GreenfootImage ("tomato.png");
setImage(image1);
getImage().scale(86,43);
}
public void act()
{
if (isTouching(snake.class))
{
MyWorld w = (MyWorld) getWorld();
getWorld().removeObject(this);
w.addPoint();
w.newHealthy();
switchImage();
}
}
public void switchImage()
{
if (getImage() == image1)
{
setImage(image2);
getImage().scale(67,66);
MyWorld w = (MyWorld) getWorld();
}
else if(getImage() == image2)
{
setImage(image3);
getImage().scale(76,78);
MyWorld w = (MyWorld) getWorld();
}
else if(getImage() == image3)
{
setImage(image1);
getImage().scale(86,43);
MyWorld w = (MyWorld) getWorld();
}
}
}