All right, I am trying to make a working healthbar for my game done in direct x 9 and for some reason nothing I do works. Basically, when I run the game and the main character collides with an enemy, the red bar for his health just travels towards the right instead of depleting to the left.
When I took a closer look I noticed that the life bars are set into the vector3D. Meaning that the health bar travels in the positive x direction. What I need is to know the steps to make a working health bar. Below are the code snippets that I have in order top create a healthbar.
//////////////////////////////////////
//Initializing the textures and the //
//Info //
/////////////////////////////////////
//Hero's Life Bar
D3DXCreateTextureFromFileEx(m_pD3DDevice,"LifeBar_Layer1_White.png",0,0,0,0,
D3DFMT_UNKNOWN,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,
D3DCOLOR_XRGB(255,255,255),&m_LifeBarImageInfo_Layer_1,0,&m_LifeBarTexture_Layer_1);
/* This is where the problem lies */
m_pD3DSprite->Draw(m_LifeBarTexture_Layer_3,0,&D3DXVECTOR3((int)m_LifeBarImageInfo_Layer_3.Width * (float)(LifeBar_Hero/100.0f),
m_LifeBarImageInfo_Layer_3.Height,0.0f),0,D3DCOLOR_ARGB(255,255,0,0));
/*****************************************************************************/
/////////////////////////////////////////////
//Updating the hero's collision with the enemies
//////////////////////////////////////////////
for(int i = 0; i < 8; i++)
{
if((m_MainPosition.z > PosEnemy[i].z - 5.0f)&&(m_MainPosition.z < PosEnemy[i].z + 5.0f))
{
if((m_MainPosition.x > PosEnemy[i].x - 5.0f)&&(m_MainPosition.x < PosEnemy[i].x + 5.0f))
{
LifeBar_Hero += 1.0f;
}
}
}