Game Development Reference
In-Depth Information
// Set default color to white
DrawColor = Default.WhiteColor;
DrawColor.B = 16;
// If our HP is > 80%, decrease the amount of red
if (HealthX > 0.8)
{
DrawColor.R = 112;
}
// If our HP is < 40%, decrease the amount of green
else if (HealthX < 0.4 )
{
DrawColor.G = 80;
}
DrawColor.A = Alpha;
BackColor = default.WhiteColor;
BackColor.A = Alpha;
/** Health bar texture */
DrawBarGraph(X,Y,Width,MaxWidth,Height,
DrawCanvas,DrawColor,BackColor);
}
In the preceding code, you'll see that we've set our default color to white, but
immediately after we've subtracted the amount of blue from 255 (full color)
to 15. We could have just created our own variable for this, for example, full
color ; but this works just as well.
If our health is higher than 80 percent, then decrease the amount of red, thereby
giving this a bit of an orange/yellow tint. That's what actually allows for this to look
green when we have a full health bar. The next if statement declares that if we drop
dangerously low to 40 percent of health or less, then we need to decrease the green
value and paint the bar red.
 
Search Nedrilad ::




Custom Search