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

2016/4/25

Death Condition

aprianil aprianil

2016/4/25

#
How to make death condition like this in greenfoot ? https://youtu.be/pmSAG51BybY i tried so many option but it didn't work like what i expect.
danpost danpost

2016/4/25

#
Explain what you mean by "death condition". If it is when you want a death to occur, then (in this case) it would be something like:
Actor enemy = getOneIntersectingObject(Enemy.class))
if (enemy != null && enemy.getY() < this.getY())
{
    // die code
}
aprianil aprianil

2016/4/25

#
the death condition is when i step the enemy , it would be die . I make multiplayer fighting game , so i need to take down my enemy when i step the enemy head until 5 times , how it would be ? thanks for help danpost. i am sorry for my English.
danpost danpost

2016/4/26

#
Add an instance int field to the class of the Enemy. Every time an instance of that class gets stepped on, increment the value of its field. Immediately after the incrementing, check its value to see if it is 5 or not. If so, have it remove itself.
JonSkyWalker JonSkyWalker

2016/4/26

#
So the code you gave should work? but we need to add an instance int field in the class of the enemy?
danpost danpost

2016/4/26

#
JonSkyWalker wrote...
So the code you gave should work? but we need to add an instance int field in the class of the enemy?
This is an internal counter here. In your case, I thought you had a healthbar that is shown. The healthbar might have the instance int field in its class.
You need to login to post a reply.