Hello I was wondering how you can create an enemy that can take more than one hit from a gun or something like that.
private Rocket myShip;
private int hitcounter = 3;
public Shot(Rocket myShip)
{
setImage("beeper.png");
getImage().scale(25, 25);
this.myShip = myShip;
setRotation(myShip.getRotation());
}
public void act()
{
move(5);
if((this.getX() < 5 || this.getX() > this.getWorld().getWidth() - 5) && (this != null))
{
this.getWorld().removeObject(this);
return;
}
if((this.getY() < 5 || this.getY() > this.getWorld().getHeight() - 5) && (this != null))
{
this.getWorld().removeObject(this);
return;
}
Actor ball = getOneIntersectingObject(Target.class);
if (hitcounter == 0) {
getWorld().removeObject(ball);
}
if (ball != null) {
hitcounter = hitcounter - 1;
getWorld().removeObject(this);
return;
}
}Target target = (Target)getOneIntersectingObject(Target.class);
if (target != null)
{
target.takeDamage();
getWorld().removeObject(this);
return;
}private int hitcounter = 3;
public void act()
{
if (hitcounter == 0)
{
getWorld().removeObject(this);
}
}
public void takeDamage()
{
hitcounter = hitcounter - 1;
}public void act()
{
move(5);
if((this.getX() < 5 || this.getX() > this.getWorld().getWidth() - 5) && (this != null))
{
this.getWorld().removeObject(this);
return;
}
if((this.getY() < 5 || this.getY() > this.getWorld().getHeight() - 5) && (this != null))
{
this.getWorld().removeObject(this);
return;
}
Target target = (Target)getOneIntersectingObject(Target.class);
if (target != null)
{
target.takeDamage();
getWorld().removeObject(this);
return;
}
}