So I have a health Variable in each enemies, and I have a damage value in the projectile class. I am quite lost. Is there a way so that i can make the projectile take health away from the enemy?
Enemy e = (Enemy) getOneIntersectingObject(Enemy.class);
if (e != null)
{
//if health is public:
e.health--;
if (e.health < 1)
{
getWorld().removeObject(e);
}
//OR, if health is private:
e.setHealth(e.getHealth()-1);
if (e.getHealth() < 1)
{
getWorld().removeObject(e);
}
}public void setHealth(final int newHealth)
{
health = newHealth;
}
public int getHealth()
{
return health;
}public void destroyEnemies(double Damage) {
Actor wedge = getOneIntersectingObject(Wedge.class);
Actor boss_wedge = getOneIntersectingObject(Boss_Wedge.class);
Actor tank = getOneIntersectingObject(Tonk.class);
Actor boss_tank = getOneIntersectingObject(Boss_Tonk.class);
Actor box = getOneIntersectingObject(Box.class);
Actor boss_box = getOneIntersectingObject(Boss_Box.class);
Actor mega = getOneIntersectingObject(Mega.class);
Actor super_boss_mega = getOneIntersectingObject(SuperBoss_Mega.class);
if (wedge != null){
Wedge.NewHP -= Damage;
getWorld().removeObject(this);
}wedge.NewHP -= Damage;
Enemy enemy = (Enemy) getOneIntersectingObject(Enemy.class);