UnrealScript Game Programming Cookbook

(Chris Devlin) #1

HUD


206

**********************************************************/
function DrawAmmoText()
{
local Vector2D TextSize, AmmoTextOffsetPOS;
local String Text;

/** Sets the variables */
Text = AmmoCount @ "|" @ MaxAmmo;

//** Offsets the text from the bar */
AmmoTextOffsetPOS = HudOffset(POS, AmmoTextOffset,);

//** Draws text */
Canvas.Font = TutFont;
Canvas.SetDrawColorStruct(WhiteColor);
Canvas.SetPos(AmmoTextOffsetPOS.X,AmmoTextOffsetPOS.Y);
Canvas.DrawText
(Text,,TextScale * ResScaleY,TextScale * ResScaleY);
Canvas.TextSize(AmmoCount, TextSize.X, TextSize.Y);
}

Our entire function should now look like this:
/**********************************************************
* Draws the ammo text and bar
**********************************************************/
function DrawAmmoText()
{
local Vector2D TextSize, POS, AmmoTextOffsetPOS;
local Int AmmoCount, MaxAmmo;
local String Text;

/** Sets the variables */
AmmoCount = UTWeapon(PawnOwner.Weapon).AmmoCount;
MaxAmmo = UTWeapon(PawnOwner.Weapon).MaxAmmoCount;
Text = AmmoCount @ "|" @ MaxAmmo;

/** Sets the current bar position */
POS = CorrectedHudPOS
(AmmoPosition,AmmoCoords.UL,AmmoCoords.VL);

/** Offsets the text from the bar */
AmmoTextOffsetPOS = HudOffset(POS, AmmoTextOffset,);

/** Draws text */
Canvas.Font = TutFont;
Canvas.SetDrawColorStruct(WhiteColor);
Canvas.SetPos(AmmoTextOffsetPOS.X,AmmoTextOffsetPOS.Y);
Canvas.DrawText
(Text,,TextScale * ResScaleY,TextScale * ResScaleY);
Canvas.TextSize(AmmoCount, TextSize.X, TextSize.Y);
Free download pdf