UnrealScript Game Programming Cookbook

(Chris Devlin) #1

HUD


202

Getting ready


Open your IDE and have it ready to edit our TutorialHUD class again. We're only going to
make changes to this class, all of which will be similar to what we've done already as now
we've established a solid base to work from.


How to do it...


This is going to be very similar to the steps we took in the recipe for our health. The only
major change we need to make here is to the properties we'll be accessing and using.
Rather than displaying our pawn's health, we'll be using the ammo property for our
pawn's currently equipped weapon.



  1. Let's begin by adding our variables. We won't need many, as we have a solid
    foundation already.
    /* Positoning for Ammo bar and text /
    var vector2d AmmoPosition, AmmoTextOffset;
    var TextureCoordinates AmmoCoords;

  2. We need a function to draw our ammo. For now we'll just call it DrawAmmoText(), as
    it will be used to draw text in the next recipe.
    /**

    • Draws the ammo text and bar
      **/
      function DrawAmmoText()
      {
      local Vector2D POS;
      local Int AmmoCount, MaxAmmo;




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

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

/** Draws Ammo Bar */
DrawAmmoBar
(POS.X, POS.Y, AmmoCount, MaxAmmo, 80, Canvas);
}

This looks very similar to our DrawHealthBarText() function used in the previous
chapter. We set our AmmoCount and MaxAmmo variables by pulling these values
from our pawn's currently selected weapon.
Free download pdf