Game Development Reference
In-Depth Information
How to do it...
For this recipe, we'll take what we learned in our previous recipe and add more functionality
onto it. A colored health bar is great, but sometimes it's nice to know the exact amount of health
remaining. Therefore we're going to add an integer next to our bar to give an exact number.
1.
Let's start by adding our new variables.
/** Stores the HUD font*/
var Font TutFont;
/** Stores how large the text should be displayed on screen*/
var float TextScale;
2.
We need to make some additions to our DrawHealthText() function.
/** Draws text */
Canvas.Font = TutFont;
Canvas.SetDrawColorStruct(WhiteColor);
Canvas.SetPos(HPTextOffsetPOS.X,HPTextOffsetPOS.Y);
Canvas.DrawText
(HPAmount,,TextScale * ResScaleY,TextScale * ResScaleY);
Canvas.TextSize(HPAmount, TextSize.X, TextSize.Y);
We're calling a number of functions from the Canvas class here. We're setting the
font as TutFont , which in our Defaultproperties block we will later declare to
be I_Fonts.MultiFonts.MF_HudLarge . Then we set the position of our text,
using HPTextPoffsetPOS , which we grab from our HudOffset() function.
We'll cover this shortly.
We want to draw our text, so we define what our HPAmount and HpAmountMax
variables are with the following bit of code:
HPAmount = PlayerOwner.Pawn.Health;
HpAmountMax = PlayerOwner.Pawn.HealthMax;
We also needed to define a size for the text though, so we multiply our TextScale
variable by the ResScaleY variable, which is the resolution size of the game.
The whole function should now look like the following code snippet:
/**********************************************************
* Draws the health text and bar
**********************************************************/
function DrawHealthText()
{
local Vector2D TextSize, POS, HPTextOffsetPOS;
local int HPAmount, HPAmountMax;
 
Search Nedrilad ::




Custom Search