I have no compiling problem, but as i play the game, the goldenNutSmall won't dissappear, eventhough my Squirrelis in the correct layer.
The Squirrel can move forward and backwards, the z value. If it is in the back layer, the layer value is over 1, and therefore my goldenNutSmall should remove itself as it touches the Squirrel, but it doesn't. Can anyone help me with this?
World (Sworld)
Squirrel
and goldenNutSmall
i copied only the important parts of Sworld and GoldenNutSmall, but the entirity of Squirrel.
Thanks
public Sworld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(660, 495, 1);
GreenfootImage background = getBackground();
theSquirrel= new Squirrel();
}
public Squirrel getSquirrel()
{
return theSquirrel;
}
}
private GreenfootImage image1;
private GreenfootImage image2;
private GreenfootImage image3;
private int layer = 1;
public void act()
{
move();
checkKeys();
giveZ();
}
public int giveZ()
{
int Z = layer;
return Z;
}
public Squirrel()
{
image1 = new GreenfootImage("egern1.png");
image2 = new GreenfootImage("egern2.png");
image3 = new GreenfootImage("egern3.png");
setImage(image1);
}
public void checkKeys()
{
movement.setLength(0.0);
movement.setDirection(0);
if (Greenfoot.isKeyDown("left"))
{
movement.setLength(10.0);
movement.setDirection(180);
}
if (Greenfoot.isKeyDown("right"))
{
movement.setLength(10.0);
movement.setDirection(0);
}
if (Greenfoot.isKeyDown("up"))
{
setImage(image2);
Greenfoot.delay(2);
setImage(image3);
layer = layer + 1;
}
if (Greenfoot.isKeyDown("down"))
{
setImage(image2);
Greenfoot.delay(2);
setImage(image1);
layer = layer - 1;
}
}
} public void act()
{
move();
fall();
checkCollision();
}
public void fall()
{
addForce(new Vector(90, 0.8));
}
public void checkCollision()
{
Actor a = getOneIntersectingObject(Squirrel.class);
if (a != null)
{
Sworld sworldy = (Sworld) getWorld();
Squirrel zsquirrel = sworldy.getSquirrel();
int Z = zsquirrel.giveZ();
if (Z > 1)
{
sworldy.removeObject(this);
}
}
}
}
