This site requires JavaScript, please enable it in your browser!
Greenfoot back
Zelmarea
Zelmarea wrote ...

2013/10/17

Health help

Zelmarea Zelmarea

2013/10/17

#
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(); } }
You need to login to post a reply.