Advertisement
Dunedune

Healthbar stuff

Jan 3rd, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1.  
  2.     // Dunedune: render health bar
  3.     if(pInfo.m_Local && g_Config.m_GfxHealthBar)
  4.     {
  5.         int hp = m_pClient->m_Snap.m_pLocalCharacter->m_Health;
  6.        
  7.         vec3 red = vec3(0.9f,0.1f,0.1f), orange = vec3(0.9f,0.45f,0.1f), yellow = vec3(0.9f, 0.9f, 0.1f), green = vec3(0.1f,0.8f,0.1f);
  8.         vec3 color;
  9.         // 1 = RED ... 5 = ORANGE ... 10 = GREEN
  10.         if(hp > 10) hp = 10;
  11.        
  12.         if(hp <= 4)
  13.             color = vec3_factor((float)(hp-1)/3.f,orange) + vec3_factor((float)(4-hp)/3.f,red);
  14.         else if(hp < 6)
  15.             color = vec3_factor((float)(hp-4)/2.f,yellow) + vec3_factor((float)(6-hp)/2.f,orange);
  16.         else if(hp == 6)
  17.             color = vec3(0.85f, 0.85f, 0.1f);
  18.         else color = vec3_factor((float)(hp-6)/4.f,green) + vec3_factor((float)(10-hp)/4.f,yellow);
  19.        
  20.         CUIRect r;
  21.         r.w = 70;
  22.         r.h = 5;
  23.         r.x = Position.x-r.w/2;
  24.         r.y = Position.y-30-r.h;
  25.        
  26.         const int Scale = 1;
  27.        
  28.        
  29.         // Draw a black round rect (ugly way)
  30.         {
  31.             vec4 c = vec4(color.r/2,color.g/2,color.b/2, 1.0f);
  32.             CUIRect q;
  33.             q.w = r.w + 2*Scale;
  34.             q.h = Scale;
  35.             q.x = r.x - Scale;
  36.             q.y = r.y + r.h;
  37.             RenderTools()->DrawUIRect(&q, c, 0, 1.0f);
  38.            
  39.             q.y = g_Config.m_GfxHealthBar == 1 ? r.y - r.h - 2 * Scale : r.y - r.h - Scale;
  40.             RenderTools()->DrawUIRect(&q, c, 0, 1.0f);
  41.            
  42.             q.w = Scale;
  43.             q.h = 2*r.h + 2*Scale;
  44.             q.x = r.x - Scale;
  45.             RenderTools()->DrawUIRect(&q, c, 0, 1.0f);
  46.            
  47.             q.x = r.x + r.w;
  48.             RenderTools()->DrawUIRect(&q, c, 0, 1.0f);
  49.            
  50.             if(g_Config.m_GfxHealthBar == 1)
  51.             {
  52.                 q.w = r.w + 2*Scale;
  53.                 q.h = Scale;
  54.                 q.x = r.x - Scale;
  55.                 q.y = r.y - Scale;
  56.                 RenderTools()->DrawUIRect(&q, c, 0, 1.0f);
  57.             }
  58.         }
  59.        
  60.        
  61.         int armor = m_pClient->m_Snap.m_pLocalCharacter->m_Armor;
  62.         if(armor > 10) armor = 10;
  63.         if(!g_Config.m_GfxArmorUnderHealth)
  64.         {
  65.             // Render health bar
  66.             r.w = 70.0f * (float)hp/10.f;
  67.             RenderTools()->DrawUIRect(&r, vec4(color.r, color.g, color.b, 0.9f), 0, 5.0f);
  68.                
  69.             // Render armor bar
  70.             if(armor)
  71.             {
  72.                 r.w = 70 * (float)armor/10;
  73.                 r.y -= g_Config.m_GfxHealthBar == 1 ? r.h + Scale : r.h;
  74.                 color = vec3(0.9f, 0.6f, 0.1f);
  75.                 RenderTools()->DrawUIRect(&r, vec4(color.r, color.g, color.b, 0.9f), 0, 5.0f);
  76.             }
  77.         }
  78.         else
  79.         {
  80.             // Render armor bar
  81.             if(armor)
  82.             {
  83.                 r.w = 70.0f * (float)armor/10;
  84.                 RenderTools()->DrawUIRect(&r, vec4(0.9f, 0.6f, 0.1f, 0.9f), 0, 5.0f);
  85.             }
  86.             r.y -= g_Config.m_GfxHealthBar == 1 ? r.h + Scale : r.h;
  87.            
  88.             // Render health bar
  89.             r.w = 70.0f * (float)hp/10.f;
  90.             RenderTools()->DrawUIRect(&r, vec4(color.r, color.g, color.b, 0.9f), 0, 5.0f);
  91.         }
  92.         r.x -= 5;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement