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

2019/3/29

Make an actor take Damage

dammnn dammnn

2019/3/29

#
I want an actor to be removed after I hit it 5 times. I shoot with the Actor "Laser" and I want "Flieger" to be removed after getting hit 5x. Here is my Code of the Flieger class:
public class Flieger extends Actor
{
public void act()
{
move South();
takeDamage();
}
int b = 0;
public void takeDamage()
{
if(isTouching(Laser.class))
{
b++;
}
if(b > 4)
{
getWorld().removeObject(this);
return;
}
}
}
Can sb help me pls?
danpost danpost

2019/3/29

#
You need to do one of the following: (1) immediately remove any laser that hits the actor; (2) add a boolean field to track the state the actor being hit by a Laser object; or (3) add an Actor reference field to hold any Laser object currently touching the actor.
You need to login to post a reply.