Hey guys, so I wanted my controllable class (savior) to be able to endure 4 separate intersecting encounters with my rocket class. The idea is that, the savior's initial health is 100, and you lose 25 every time the savior comes into contact with the rocket. But when I test this out, my savior object disappears on the first interaction.
public class Savior extends Actor
{
/**
* Act - do whatever the Savior wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
int health = 100;
public void act()
{
if(Greenfoot.isKeyDown("a")){
move(-3);
}
if(Greenfoot.isKeyDown("d")) {
move(3);
}
if(Greenfoot.isKeyDown("w")) {
getWorld().addObject(new Missile(), this.getX(), this.getY());
}
Hit();
if( health == 0) {
getWorld().removeObject(this);
}
}
public void Hit()
{
Actor rocket;
rocket = getOneObjectAtOffset(0, 0, Rocket.class);
if(isTouching(Rocket.class)) {
getWorld().removeObject(rocket);
health = health - 25;
}
}
}
