void draw_opp_health(HDC hdc)
{
HPEN hPenOld;
HPEN hLinePen;
COLORREF bar_colour;
if (opponent.current_hp / opponent.max_hp > 0.5) // Green > 50% health
{
bar_colour = RGB(55, 220, 30);
}
else if (opponent.current_hp / opponent.max_hp > 0.1) // Yellow > 10% health
{
bar_colour = RGB(225, 225, 0);
}
else // Red < 10% health
{
bar_colour = RGB(225, 0, 0);
}
hLinePen = CreatePen(PS_SOLID, 7, bar_colour);
hPenOld = (HPEN)SelectObject(hdc, hLinePen);
health_bar = ((opponent.current_hp / opponent.max_hp) * 150) + 110;
// int // int starts at 100 // const int 100 //positioning the health bar
// Opponents health
MoveToEx(hdc, 110, 113, NULL);
LineTo(hdc, health_bar, 113);
SelectObject(hdc, hPenOld);
DeleteObject(hLinePen);
}
I'm trying to redraw the health bar to a percentage of its maximum amount (changing colours as health decreases).
So (as of this testing phase) when I click the left mouse button, opponent.current_hp decreases by 20 and i redraw the window.
Initially, when it's all drawn, current_hp is 100 and max_hp is 100 so health_bar evaluates to 260 and the line is drawn properly. Then on my first click the line is redrawn red and short (essentially a circle... I'm pretty sure it's a line of length 0 but the computer can't do that... Either way, not important right now).
Can anyone tell me why the line isn't being redrawn 20% shorter each time?