This is part of what I have:
while (hoverEnemy == true)
{
window.draw(cop);
std::cout << "Hover\n";
if (clickEnemy)
{
numofclicks + 1;
std::stringstream text;
text << "Cop has " << EnemyObject.eHp(copHitPoints, numofclicks) << " hp left ";
copHp.setString(text.str());
window.draw(copHp);
std::cout << "Clicked\n";
if(copHitPoints == 0)
{
EnemyObject.die();
}
clickEnemy = false;
}
hoverEnemy = false;
}
What I want to do is make the health (copHitPoints) go down by 20 every click. The problem is when I set the clickEnemy to false at the end of the code above window.draw(copHp) pops up for a slight second. But when I leave out the clickEnemy = false; click is set to true infinity. What I also want is for the window.draw(cop) to "undraw" when clickEnemy is true.
The EnemyObject.eHp code:
int eHp(int intialHp, int numClicks)
{
if (numClicks == 1)
{
intialHp = 80;
return intialHp;
}
if (numClicks == 2)
{
intialHp = 60;
return intialHp;
}
if (numClicks == 3)
{
intialHp = 40;
return intialHp;
}
if (numClicks == 4)
{
intialHp = 20;
return intialHp;
}
if (numClicks == 5)
{
intialHp = 0;
return intialHp;
}
if (numClicks < 6)
{
intialHp = 0;
return intialHp;
}
}