Creating a shield for an enemy class

So say if I want to create a shield so that you would have to take down the shield before killing the enemy. How would I code that?

1 Like

If the enemies are invulnerable before you destroy the shield you could do something like

//enemy die check
if(hasShield==false&&lives<0) destroyed();

otherwise you can just do something like

void damaged(int dmg) {
   if(shieldPoints>0) shieldPoints -= dmg;
   if(shieldPoints<0) {
       lifePoints+=shieldPoints;  //since shield points are less than 0, so addition will lower the number     
      shieldPoints = 0;
   } else lifePoints-=dmg;
//only display shield if shieldPoints>0

EDIT: there is a bug. I should not have used else lifePoints-=dmg since that would never happen with shieldPoints equal or lower to 0. I fixed it now, so the condition is shieldPoints<0 instead of <=