Adding hunger, thirst, etc. bars
by N · in Torque Game Engine · 10/20/2004 (3:46 pm) · 4 replies
Would someone please tell me where I could find a tutorial on how to create a bar similar to the health bar to show things like hunger, thirst, temperature, etc...
About the author
#2
Hunger/Thirst/Temperature will be variables you will have to add in of course
10/20/2004 (4:06 pm)
The gui for health is pretty bare bones, just look how it takes the damage Level or energy level and handels it.Hunger/Thirst/Temperature will be variables you will have to add in of course
#3
In shapebase.h, after F32 getEnergyValue(); add:
After F32 mEnergy; Add:
In shapebase.cc in ShapeBase::ShapeBase() Add:
after F32 ShapeBase::getEnergyValue() Add:
then add this:
Then add:
Hope this helps.
Now you can choose the display Hunger the gui control, and set the hunger level (between 0.0 and 1.0) with.
%object.setHungerLevel(%hunger);
You can do the same for thirst, temp etc..
10/20/2004 (4:25 pm)
Part2 (Shapebase).In shapebase.h, after F32 getEnergyValue(); add:
F32 getHungerValue();
After F32 mEnergy; Add:
F32 mEnergy;
In shapebase.cc in ShapeBase::ShapeBase() Add:
mHunger = 0.0;
after F32 ShapeBase::getEnergyValue() Add:
F32 ShapeBase::getHungerValue()
{
F32 maxHunger 1.0;
if ( maxEnergy > 0.f )
{
return (mHunger / maxHunger);
}else{
return 0.0f;
}
}then add this:
void ShapeBase::setHungerLevel(F32 hunger)
{
if (mDamageState == Enabled) {
mHunger = (energy > 1.0)?
1.0: (energy < 0)? 0.0: hunger;
}
}Then add:
ConsoleMethod( ShapeBase, setHungerLevel, void, 3, 3, "(float myhunger)")
{
object->setHungerLevel(dAtof(argv[2]));
}-----------------------------------------------Hope this helps.
Now you can choose the display Hunger the gui control, and set the hunger level (between 0.0 and 1.0) with.
%object.setHungerLevel(%hunger);
You can do the same for thirst, temp etc..
#4
cheers,
Robert
10/20/2004 (5:01 pm)
Gui's are client side. I think you want to write this data to the client also. Check out ShapeBase::setDamageLevel() to see what I mean. Changes to server data get sent to the client, if they have their mask bits set. A Gui would need to grab that from the player object on the client and that data would get there by this means. Might also look at ShapeBase::packUpdate(cheers,
Robert
Torque Owner Westy
It currently takes energy into account, so replicate this for whatever property you want to show.
Lets take huner as the example (as a percentage/factor 0.0 to 1.0).
--------------------------------------------------------------------------------------
In GuiHealthBarHud::GuiHealthBarHud() add:
In GuiHealthBarHud::initPersistFields() add:
In GuiHealthBarHud::onRender, change the If statement to:
if(mDisplayEnergy) { mValue = control->getEnergyValue(); } else if(mDisplayHunger) { mValue = control ->getHungerValue(); } else { // We'll just grab the damage right off the control object. // Damage value 0 = no damage. mValue = 1 - control->getDamageValue(); }