Posted by zero Fri 2nd Mar 2007 19:05 - Syntax is Lua - 48 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
-
Panel.DeriveNewClass( 'HudHealth' )
-
-
HudHealth.New()
-
-
function HudHealth:Init()
-
-
self:SetAlignment( kAlignBottom )
-
self:SetBounds( 16, 16, 200, 48 )
-
-
local empty = Image.New( self, kAlignMiddle )
-
-
empty:SetCharacter( '?', kSymbolFont )
-
empty:SetFgColor( kNone )
-
empty:FadeTo( kDim, kDelay )
-
-
local full = Image.New( self, kAlignMiddle )
-
-
full:SetCharacter( '?', kSymbolFont )
-
full:SetFgColor( kNone )
-
full:FadeTo( kBright, kDelay )
-
-
local number = Label.New( self, kAlignMiddle )
-
-
number:SetText( '', kNumberFont )
-
number:SetBounds( 48, 0, 128, 48 )
-
number:SetFgColor( kNone )
-
-
self.empty = empty
-
self.full = full
-
self.number = number
-
-
end
-
-
p = Player:New()
-
-
function HudHealth:OnThink()
-
-
self.value = p:GetHealth()
-
-
local number = self.number
-
local full = self.full
-
-
-
if self.value ~= tonumber( number:GetText() ) then
-
-
if self.value < 50 then
-
number:FadeTo( kDanger, 1 )
-
else
-
number:FadeTo( kBright, 1 )
-
number:SetOverbright( 3.75 )
-
end
-
-
number:SetText( self.value )
-
-
end
-
-
full:Clip( 0, (1 - (self.value/100)) * full:GetHeight(), 0, 0 )
-
-
end
-
-
function HudHealth:OnPaint()
-
-
local number = self.number
-
local overbright = number:GetOverbright()
-
-
if self.value < 50 then
-
number:SetOverbright( math.abs(math.cos(Globals.curtime() * 3)) * 3.75 )
-
-
elseif overbright > 0 then
-
number:SetOverbright( math.max(0, overbright - Globals.frametime() * 2.5) )
-
-
end
-
-
end
-
-
function HudHealth:IsVisible()
-
-
if self.value <= 0 then
-
return false
-
end
-
-
return true
-
-
end
-
PermaLink to this entry https://pastebin.co.uk/11307
Posted by zero Fri 2nd Mar 2007 19:05 - Syntax is Lua - 48 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Comments: 0