UnrealScript Game Programming Cookbook

(Chris Devlin) #1
Chapter 7

207

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

This should look very similar to what we have for our health bar text. Again, we're
using our AmmoCount and MaxAmmo count, just as we did for our ammo bar. We are
offsetting the text from our ammo bar, but because the bar is on the right side of the
screen we won't have any room to display the text to the right. Therefore, we're going
to offset it to the left.
Our Text variable consists of our pawn's weapon's current ammo, followed by the @
sign, which concatenates the string. I've placed a | character in quotes to divide the
current ammo variable from the maximum ammo variable as well.


  1. Of course, let's not forget to add our variable to our DefaultProperties block.
    We'll be offsetting our text -108 pixels from the right-hand corner of our ammo bar,
    so that the text is placed right where the bar ends.


-108 pixels may not always be enough space to fit your ammo count; you
may want to consider offsetting it by a different value if you are using a
weapon whose ammo count may be more than five characters in length.

// Offsets text from bar
AmmoTextOffset=(X=-108, Y=0)


  1. Compile the code and take a look; we've got text on screen to represent our
    current and maximum ammo capacity!

Free download pdf