Trying to make a healthbar with windows.h

I'm having a bit of trouble, thought I could ask here rather than failing a few more times.

I'm trying to make a circular healthbar for my player using windows.h library only (not only my knowledge limitations but my project limitations too).

I tried something like this

In a separate function, the _fWidthDivisor would be calculated by going
1
2
float fHeightDivisor = fMaxHealth/fCurrentHealth;
Draw(1, fHeightDivisor, 0)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void CSprite::Draw(float _fWidthDivisor, float _fHeightDivisor, int _iWidthAddition)
{
	float fW = GetWidth()/_fWidthDivisor;
	float fH = GetHeight()/_fHeightDivisor;

	float SCREEN_OFFSET_X = CGame::GetInstance().GetLevel()->m_Camera->GetScreenOffsetX();
	float SCREEN_OFFSET_Y = CGame::GetInstance().GetLevel()->m_Camera->GetScreenOffsetY();

	float fX = m_fX - (fW/2) - SCREEN_OFFSET_X;
	float fY = m_fY - (fH/2) - SCREEN_OFFSET_Y;

	CBackBuffer* pBackBuffer = CGame::GetInstance().GetBackBuffer();

	HGDIOBJ hOldObj = SelectObject(s_hSharedSpriteDC, m_hMask);

	BitBlt(pBackBuffer->GetBackDC(), fX, fY, fW, fH, s_hSharedSpriteDC, 0, 0, SRCAND);

	SelectObject(s_hSharedSpriteDC, m_hSprite);

	BitBlt(pBackBuffer->GetBackDC(), fX, fY, fW, fH, s_hSharedSpriteDC, 0, 0, SRCPAINT);

	SelectObject(s_hSharedSpriteDC, hOldObj);
}


the problem with this is, the BitBlt functions casts everything as an int, so the iWidthDivisor will jump from 1, to 2, to 3, and truncate any float values, i.e. cannot show anything between 50-100% health, will jump between either two.

Now I'm aware I could make a healthbar using pixels and add one pixel for every 1% of health, but my healthbar is a circle rather than a bar, so I'm not sure how I'd get it to work

What I said is pretty obvious, but just so that everyone can visually see what I mean - I was hoping someone could suggest a way I could make a healthbar that looks like this - considering my BitBlt is truncating values between

http://oi46.tinypic.com/t4w9op.jpg

Thanks in advance
Would it make sense to simply fill a RECT area and then clip out the circle before drawing? For example, using a backbuffer:

- Clear the backbuffer
- Fill the health area RECT
- Copy circle mask on top
- Draw backbuffer to screen with transparency
That sounds like a good idea thanks for the suggestion.

So basically I would have an array of say 100 "bars" and for each 1% of health there is I would be drawing 1 bar?

It just seems like it could be inefficient to me to have 100 images when I could have one that clips out, which is why I wanted a way around it, but I'll get to work on what you suggested for now anyway

Thanks again
Topic archived. No new replies allowed.