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

2013/5/6

Life code

GhostSniper GhostSniper

2013/5/6

#
I'm trying to make a game with lives in it and trying to make the heart object disappear. Does anybody know the code?
holla holla

2013/5/7

#
All you need is a counter (like int lifes = 3;) and an object with the heartshape image on it. then you place the desired hearts in your world and if someone is dead, then
 lifes = lifes -1; 
if (lifes==2)
{removeObject(heart3);}
if (lifes==1)
{removeObject(heart2);}
if (lifes==0)
{removeObject(heart1);
Greenfoot.stop(); //or what else}
There are some simplier ways to do it, but i am not a profi. And don't forget to instance the three hearts at the beginning like: Heart heart1 = new Heart(); Heart heart2 = new Heart(); Heart heart3 = new Heart(); So you can directly "contact" each object with their own name.
GhostSniper GhostSniper

2013/5/15

#
So who do I decease the number of lives when my actor gets hit
You need to login to post a reply.