Game Development Reference
In-Depth Information
We offset the bar's position again by using the CorrectedHudPOS() function we
used in the last recipe as well. This time however, the bar will be in the top-right
corner of the screen.
At the bottom of the function, we have a call to our DrawAmmoBar()
function, which we'll get to know in the next step. It looks nearly identical
to our DrawHealthBar() function, except that we're using our AmmoCount
and MaxAmmo variables as parameters.
3.
Let's create that DrawAmmoBar() function. It appears and operates just like
our DrawHealthBar() function in the previous recipe.
/**********************************************************
* Draw player's ammo. Adjusts the bar color based on
* available ammo
**********************************************************/
simulated function DrawAmmoBar(float X, float Y, float
Width, float MaxWidth, float Height, Canvas DrawCanvas,
optional byte Alpha=255)
{
local float AmmoX;
local color DrawColor, BackColor;
// Color of bar relies on the player's current ammo
AmmoX = Width/MaxWidth;
// Set default color to white
DrawColor = Default.WhiteColor;
// Decrease the amount of blue
DrawColor.B = 16;
// If our ammo is > 80%, decrease the amount of red
if (AmmoX > 0.8)
{
DrawColor.R = 112;
}
// If our ammo is < 40%, decrease the amount of green
else if (AmmoX < 0.4 )
{
DrawColor.G = 80;
}
DrawColor.A = Alpha;
BackColor = default.WhiteColor;
BackColor.A = Alpha;
/** Ammo bar texture */
DrawBarGraph(X,Y,Width,MaxWidth,Height,
DrawCanvas,DrawColor,BackColor);
}
 
Search Nedrilad ::




Custom Search