Game Development Community

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...

#1
10/20/2004 (4:05 pm)
Modify the GuiHealthBarHud control to read these poperties from the control objects class (most thinks you control will inherit from shapbase class).

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:

mDisplayHunger = false;

In GuiHealthBarHud::initPersistFields() add:

addField( "displayHunger", TypeBool, Offset( mDisplayHunger, GuiHealthBarHud ) );

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();
   }
#2
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
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
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