Game Development Community

RTSUnit Health Bar Color Damage

by BillF · in RTS Starter Kit · 03/16/2008 (10:32 am) · 3 replies

This is a simple modification to the existing RTSUnit health bar rendering that makes the bar show green for healthy, yellow for medium damage, and red for heavy damage.

In guiRTSTSCtrl.h

replace
ColorF   mDamageFillColor;

with
ColorF   mDamageFillColorHealthy;
ColorF   mDamageFillColorMedium;
ColorF   mDamageFillColorHeavy;

In guiRTSTSCtrl.cc

replace
mDamageFillColor.set( 0, 1, 0, 1 );

with
mDamageFillColorHealthy.set( 0, 1, 0, 1 );
mDamageFillColorMedium.set( 1, 1, 0, 1 );
mDamageFillColorHeavy.set( 1, 0, 0, 1 );

replace
dglDrawRectFill(rect, mDamageFillColor);

with
dglDrawRectFill(rect, damage<0.33f?mDamageFillColorHeavy:damage<0.66f?mDamageFillColorMedium:mDamageFillColorHealthy);

That's it, you should now have RTSUnit health bars that show green, yellow, or red based on the unit's damage level.

#1
03/16/2008 (11:15 am)
Again, well done!
#2
04/01/2008 (2:03 pm)
Good job. Will come in handy.
#3
01/19/2010 (2:23 am)
works great with tge 1.5.2