I want the actor to change its image when it hits Goomba. I tried to do it but it changes Goomba's image
line 87
import greenfoot.*;
public class Mario extends Actor
{
private int speed = 7;
private int vSpeed = 0;
private int acceleration = 2;
private int jumpStrength = 25;
private Label myLabel;
private int count = 10000;
public Mario (Label label)
{
myLabel = label;
}
public void act()
{
checkKeys();
checkFall();
hitGoomba();
hitCastle();
}
private void checkKeys()
{
if(Greenfoot.isKeyDown("left"))
{
moveLeft();
}
if(Greenfoot.isKeyDown("right"))
{
moveRight();
scoreCount();
}
if(Greenfoot.isKeyDown("up"))
{
jump();
scoreCount();
}
}
public void checkFall()
{
if(onGround() && vSpeed != -jumpStrength)
{
vSpeed=0;
if (Greenfoot.isKeyDown("left") == Greenfoot.isKeyDown("right"))
{
setImage("Mario_idle.png");
}
}
else
{
setImage("Mario_jump.png");
fall();
}
}
public void scoreCount()
{
count-=1;
myLabel.setText("SCOR: " + count);
}
public boolean onGround()
{
Actor under = getOneObjectAtOffset ( 0, getImage().getHeight()/2, Ground.class);
return under != null;
}
public void fall()
{
setLocation ( getX(), getY() + vSpeed);
vSpeed = vSpeed + acceleration;
}
public void jump()
{
if (onGround())
{
vSpeed = - jumpStrength;
}
}
public void hitGoomba()
{
Actor goomba = getOneIntersectingObject(Goomba.class);
if(goomba != null)
{
World myWorld = getWorld();
GameOver gameover = new GameOver();
myWorld.addObject(gameover, myWorld.getWidth()/2, myWorld.getHeight()/2);
myWorld.removeObject(goomba);
}
}
public void hitCastle()
{
Actor castle = getOneIntersectingObject(Castle.class);
if(castle != null)
{
World myWorld = getWorld();
GameOver_Win gameover_win = new GameOver_Win();
myWorld.addObject(gameover_win, myWorld.getWidth()/2, myWorld.getHeight()/2);
myWorld.removeObject(this);
Greenfoot.setWorld(new Level_2());
}
}
public void moveRight()
{
setLocation ( getX() + speed, getY());
setImage("Mario_walk.png");
}
public void moveLeft()
{
setLocation ( getX() - speed, getY());
setImage("Mario_walk_mirror.png");
}
}
