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.
/////////////////////////////////////
//Declaring the variables //
////////////////////////////////////
IDirect3DTexture9* m_LifeBarTexture_Layer_1;
IDirect3DTexture9* m_LifeBarTexture_Layer_2;
IDirect3DTexture9* m_LifeBarTexture_Layer_3;
D3DXIMAGE_INFO m_LifeBarImageInfo_Layer_1;
D3DXIMAGE_INFO m_LifeBarImageInfo_Layer_2;
D3DXIMAGE_INFO m_LifeBarImageInfo_Layer_3;
//////////////////////////////////////
//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);
D3DXCreateTextureFromFileEx(m_pD3DDevice,"LifeBar_Layer2_Gray.png",0,0,0,0,
D3DFMT_UNKNOWN,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,
D3DCOLOR_XRGB(194,194,194),&m_LifeBarImageInfo_Layer_2,0,&m_LifeBarTexture_Layer_2);
D3DXCreateTextureFromFileEx(m_pD3DDevice,"LifeBar_Layer3_Red.png",0,0,0,0,
D3DFMT_UNKNOWN,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,
D3DCOLOR_XRGB(255,0,0),&m_LifeBarImageInfo_Layer_3,0,&m_LifeBarTexture_Layer_3);
/////////////////////////////////////////////////////////////////
//Rendering the Healthbars
////////////////////////////////////////////////////////////////
//Life Bar - Layer 1
D3DXMatrixIdentity(&transMat);
D3DXMatrixIdentity(&rotMat);
D3DXMatrixIdentity(&scaleMat);
D3DXMatrixIdentity(&worldMat);
D3DXMatrixScaling(&scaleMat,0.5f,0.5f,0.0f);//scale code
D3DXMatrixTranslation(&transMat,200.0f,30.0f,0.0f);
D3DXMatrixRotationZ(&rotMat,D3DXToRadian(0.0f));//Rotation code
D3DXMatrixMultiply(&transMat,&scaleMat,&transMat);
D3DXMatrixMultiply(&worldMat,&rotMat,&transMat);
m_pD3DSprite->SetTransform(&worldMat);
m_pD3DSprite->Draw(m_LifeBarTexture_Layer_1,0,&D3DXVECTOR3(m_LifeBarImageInfo_Layer_1.Width,
m_LifeBarImageInfo_Layer_1.Height,0.0f),0,D3DCOLOR_ARGB(255,255,255,255));
//Life Bar - Layer 2
D3DXMatrixIdentity(&transMat);
D3DXMatrixIdentity(&rotMat);
D3DXMatrixIdentity(&scaleMat);
D3DXMatrixIdentity(&worldMat);
D3DXMatrixScaling(&scaleMat,0.5f,0.5f,0.0f);//scale code
D3DXMatrixTranslation(&transMat,200.0f,30.0f,0.0f);
D3DXMatrixRotationZ(&rotMat,D3DXToRadian(0.0f));//Rotation code
D3DXMatrixMultiply(&transMat,&scaleMat,&transMat);
D3DXMatrixMultiply(&worldMat,&rotMat,&transMat);
m_pD3DSprite->SetTransform(&worldMat);
m_pD3DSprite->Draw(m_LifeBarTexture_Layer_2,0,&D3DXVECTOR3(m_LifeBarImageInfo_Layer_2.Width,
m_LifeBarImageInfo_Layer_2.Height,0.0f),0,D3DCOLOR_ARGB(255,194,194,194));
//Life Bar - Layer 3
D3DXMatrixIdentity(&transMat);
D3DXMatrixIdentity(&rotMat);
D3DXMatrixIdentity(&scaleMat);
D3DXMatrixIdentity(&worldMat);
D3DXMatrixScaling(&scaleMat,0.5f,0.5f,0.0f);//scale code
D3DXMatrixTranslation(&transMat,200.0f,30.0f,0.0f);
D3DXMatrixRotationZ(&rotMat,D3DXToRadian(0.0f));//Rotation code
D3DXMatrixMultiply(&transMat,&scaleMat,&transMat);
D3DXMatrixMultiply(&worldMat,&rotMat,&transMat);
m_pD3DSprite->SetTransform(&worldMat);
/* 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;
}
}
}