Posted by zero Fri 2nd Mar 2007 19:05 - Syntax is Lua - 48 views
Download | New Post | Modify | Hide line numbers
  1. Panel.DeriveNewClass( 'HudHealth' )
  2.  
  3. HudHealth.New()
  4.  
  5. function HudHealth:Init()
  6.  
  7.     self:SetAlignment( kAlignBottom )
  8.     self:SetBounds( 16, 16, 200, 48 )
  9.        
  10.     local empty = Image.New( self, kAlignMiddle )
  11.  
  12.     empty:SetCharacter( '?', kSymbolFont )
  13.     empty:SetFgColor( kNone )
  14.     empty:FadeTo( kDim, kDelay )
  15.  
  16.     local full = Image.New( self, kAlignMiddle )
  17.  
  18.     full:SetCharacter( '?', kSymbolFont )
  19.     full:SetFgColor( kNone )
  20.     full:FadeTo( kBright, kDelay )
  21.  
  22.     local number = Label.New( self, kAlignMiddle )
  23.  
  24.     number:SetText( '', kNumberFont )
  25.     number:SetBounds( 48, 0, 128, 48 )
  26.     number:SetFgColor( kNone )
  27.  
  28.     self.empty = empty
  29.     self.full = full
  30.     self.number = number
  31.  
  32. end
  33.  
  34. p = Player:New()
  35.  
  36. function HudHealth:OnThink()
  37.  
  38.     self.value = p:GetHealth()
  39.    
  40.     local number = self.number
  41.     local full = self.full
  42.    
  43.        
  44.     if self.value ~= tonumber( number:GetText() ) then
  45.        
  46.         if self.value < 50 then
  47.             number:FadeTo( kDanger, 1 )
  48.         else
  49.             number:FadeTo( kBright, 1 )
  50.             number:SetOverbright( 3.75 )
  51.         end
  52.        
  53.         number:SetText( self.value )
  54.        
  55.     end
  56.  
  57.     full:Clip( 0, (1 - (self.value/100)) * full:GetHeight(), 0, 0 )
  58.  
  59. end
  60.  
  61. function HudHealth:OnPaint()
  62.    
  63.     local number = self.number
  64.     local overbright = number:GetOverbright()
  65.    
  66.     if self.value < 50 then
  67.         number:SetOverbright( math.abs(math.cos(Globals.curtime() * 3)) * 3.75 )
  68.        
  69.     elseif overbright > 0 then
  70.         number:SetOverbright( math.max(0, overbright - Globals.frametime() * 2.5) )
  71.        
  72.     end
  73.  
  74. end
  75.  
  76. function HudHealth:IsVisible()
  77.  
  78.     if self.value <= 0 then
  79.         return false
  80.     end
  81.  
  82.     return true
  83.  
  84. end
  85.  

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

 

Comments: 0