Code: Select all
#include "HUD.h"
#include "Engine.h"
HUD::HUD(video::IVideoDriver *driver,gui::IGUIEnvironment *guienv,Character* turtle1)
{
turtle=turtle1;
float width= driver->getViewPort().getWidth();
float height = driver->getViewPort().getHeight();
heart = driver->getTexture("media/heart.png");
heart2 = driver->getTexture("media/heart2.png");
guienv->addImage(driver->getTexture("media/irrlichtLogo2.png"),position2d<int>(width - 130 ,height - 130));
//guienv->addImage(driver->getTexture("media/hud.png"),position2d<int>(10,10));
guienv->addImage(heart,position2d<int>(55,10));
guienv->addImage(heart,position2d<int>(110,10));
guienv->addImage(heart,position2d<int>(165,10));
guienv->addImage(heart,position2d<int>(220,10));
guienv->addImage(heart,position2d<int>(275,10));
}
void HUD::Update(float frameDeltaTime,video::IVideoDriver *driver,gui::IGUIEnvironment *guienv)
{
if(turtle->Health <= 80)
guienv->addImage(heart2,position2d<int>(55,10));
if(turtle->Health <= 60)
guienv->addImage(heart2,position2d<int>(110,10));
if(turtle->Health <= 40)
guienv->addImage(heart2,position2d<int>(165,10));
if(turtle->Health <= 20)
guienv->addImage(heart2,position2d<int>(220,10));
if(turtle->Health <= 0)
guienv->addImage(heart2,position2d<int>(275,10));
}
HUD::~HUD(void)
{
}
Code: Select all
HUD* hud = new HUD(driver,guienv,turtle);
Code: Select all
float Lasthealth = -1.f;
float health = turtle->Health;
if(Lasthealth != health){
hud->Update(frameDeltaTime,driver,guienv);
Lasthealth = health;
}