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

2016/4/15

Health for Actors

bintin125 bintin125

2016/4/15

#
I'm trying to make a game where if the player touches an enemy, their health is lowered. How do I make it so that an enemy has to attack the player a certain number of times for them to be removed from the world.
danpost danpost

2016/4/15

#
All you need is an instance int field for the number of hits required to kill the actor. Lower its value each time the actor is hit. When the value is lowered to the value of zero, remove the actor. If the enemy is not removed when touching the actor, you will need to track the touching state to determine when the touch occurs (as opposed to knowing if it is currently touching or not). This is so that you are not be constantly decrementing the value of health while the same occurrence of the touch continues.
You need to login to post a reply.