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;
}
}
G pointed out where the problem is and now it's your task to think about how to change it, we're not here to correct your code or write you new code, we're here to help you understand where you did your mistakes and how you can fix it. And as I implied earlier programming is about logic, you need quite a good potion of it, so you should practice it with more basic elements (at best in combination with a book). ;)
A further thing I pointed out is that you should keep the draw call seperated from the logic.
So with those two points in mind it should be fairly easy to write diffrent code.
Another (repeated) hint: Create a boolean for copHp and cop and if someone clicks set the boolean of copHp to true and the boolean of cop to false. Then at the drawing part you simply do:
if(booleanOfcopHp)
window.draw(copHp);
if(booleanOfcop)
window.draw(cop);