I'm making a scenario where you play a bunny throwing knives at a slime. Right now, my code is working, but only if I have the damage done by the slime and the bunny's health equal. This is the code I've been using, in the code for the knife. The code in the slimeball section is the same just with different variable names.
private int damage = 5;
private int life = 50;
private int slimeLife = 5;
private GreenfootImage knive;
{
knive = new GreenfootImage("knife.png");
}
public void act()
{
setImage(knive);
if(life <= 0) {
getWorld().removeObject(this);
}
else {
move(-3);
Actor Slime = (Slime) getOneIntersectingObject(Slime.class);
if(Slime != null){
getWorld().removeObject(this);
slimeLife = slimeLife - damage;
}
else {
life--;
}
}
if (slimeLife<=0)
{
Greenfoot.playSound("win.wav");
Greenfoot.stop();
}
}