Browse Source

Rework health indicator code.

noffice
Andrey Akhmichin 5 years ago
parent
commit
abd3eb5e9b
  1. 107
      cl_dll/health.cpp
  2. 8
      cl_dll/health.h

107
cl_dll/health.cpp

@ -90,20 +90,12 @@ int CHudHealth::VidInit( void ) @@ -90,20 +90,12 @@ int CHudHealth::VidInit( void )
m_HUD_dmg_bio = gHUD.GetSpriteIndex( "dmg_bio" ) + 1;
m_HUD_cross = gHUD.GetSpriteIndex( "cross" );
m_HUD_health1 = gHUD.GetSpriteIndex( "health1" );
m_HUD_health2 = gHUD.GetSpriteIndex( "health2" );
giDmgHeight = gHUD.GetSpriteRect( m_HUD_dmg_bio ).right - gHUD.GetSpriteRect( m_HUD_dmg_bio ).left;
giDmgWidth = gHUD.GetSpriteRect( m_HUD_dmg_bio ).bottom - gHUD.GetSpriteRect( m_HUD_dmg_bio ).top;
int HUD_health_empty = gHUD.GetSpriteIndex( "health1" );
int HUD_health_full = gHUD.GetSpriteIndex( "health2" );
m_hSprite1 = m_hSprite2 = 0; // delaying get sprite handles until we know the sprites are loaded
m_prc1 = &gHUD.GetSpriteRect( HUD_health_empty );
m_prc2 = &gHUD.GetSpriteRect( HUD_health_full );
m_iHeight = m_prc2->bottom - m_prc1->top;
return 1;
}
@ -195,9 +187,6 @@ int CHudHealth::Draw( float flTime ) @@ -195,9 +187,6 @@ int CHudHealth::Draw( float flTime )
if( ( gHUD.m_iHideHUDDisplay & HIDEHUD_HEALTH ) || gEngfuncs.IsSpectateOnly() )
return 1;
if( !( gHUD.m_iWeaponBits & ( 1 << ( WEAPON_SUIT ) ) ) )
return 1;
int r, g, b, x, y, a;
// Has health changed? Flash the health #
@ -216,86 +205,34 @@ int CHudHealth::Draw( float flTime ) @@ -216,86 +205,34 @@ int CHudHealth::Draw( float flTime )
else
a = MIN_ALPHA;
int fDrawNewHUD = ( gHUD.m_pCvarNewHud && gHUD.m_pCvarNewHud->value == 1 ) ? TRUE : FALSE;
//
// Draw new HUD
//
if( fDrawNewHUD )
{
// ==========================================
// Code changes for- Night at the Office:
// ==========================================
//
// -Sprite based Health meter. Instead of showing the health numerically, it is represented visually.
// There are no health pick-ups so wasn't relevant to give a specific health value on the HUD.
// i.e. The closer sprite is to being covered in red, the closer you are to death.
wrect_t rc;
rc = *m_prc2;
rc.bottom -= m_iHeight * ( (float)( 100 - ( Q_min( 100, m_iHealth ) ) ) * 0.01 ); // health can go from 0 to 100 so * 0.01 goes from 0 to 1
UnpackRGB( r, g, b, RGB_WHITEISH );
if( !m_hSprite )
m_hSprite = LoadSprite( PAIN_NAME );
// If health is getting low, make it bright red
if( m_iHealth <= 15 )
a = 255;
ScaleColors( r, g, b, a );
int iOffset = ( m_prc1->bottom - m_prc1->top );
y = ScreenHeight - 5;
x = 10;
// make sure we have the right sprite handles
if( !m_hSprite1 )
m_hSprite1 = gHUD.GetSprite( gHUD.GetSpriteIndex( "health1" ) );
if( !m_hSprite2 )
m_hSprite2 = gHUD.GetSprite( gHUD.GetSpriteIndex( "health2" ) );
SPR_Set( m_hSprite1, r, g, b );
SPR_DrawHoles( 0, x, y - iOffset, m_prc1 );
GetPainColor( r, g, b );
ScaleColors( r, g, b, a );
if( m_iHealth <= 100 )
{
SPR_Set( m_hSprite2, r, g, b );
SPR_DrawHoles( 0, x, y - iOffset + ( rc.top - m_prc2->top ), &rc );
}
}
//
// Draw old HUD
//
else
// Only draw health if we have the suit.
if( gHUD.m_iWeaponBits & ( 1 << ( WEAPON_SUIT ) ) )
{
int HealthWidth;
if( !m_hSprite )
m_hSprite = LoadSprite( PAIN_NAME );
// If health is getting low, make it bright red
if( m_iHealth <= 15 )
a = 255;
GetPainColor( r, g, b );
ScaleColors( r, g, b, a );
// Only draw health if we have the suit.
if( gHUD.m_iWeaponBits & ( 1 << ( WEAPON_SUIT ) ) )
{
HealthWidth = gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).right - gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).left;
int CrossWidth = gHUD.GetSpriteRect( m_HUD_cross ).right - gHUD.GetSpriteRect( m_HUD_cross ).left;
y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2;
x = CrossWidth / 2;
int HealthHeight = gHUD.GetSpriteRect( m_HUD_health1 ).bottom - gHUD.GetSpriteRect( m_HUD_health1 ).top;
y = ScreenHeight - HealthHeight - HealthHeight / 6;
x = 10;
SPR_Set(gHUD.GetSprite( m_HUD_cross ), r, g, b );
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( m_HUD_cross ) );
float delimeter = ( 100.0f - m_iHealth ) * 1.28f;
x = CrossWidth + HealthWidth / 2;
SPR_EnableScissor( x, y - delimeter, 96, 128 );
SPR_Set( gHUD.GetSprite( m_HUD_health2 ), 255, 255, 255 );
SPR_DrawHoles( 0, x, y, 0 );
SPR_DisableScissor();
x = gHUD.DrawHudNumber( x, y, DHN_3DIGITS | DHN_DRAWZERO, m_iHealth, r, g, b );
}
SPR_EnableScissor( x, ( y + 128 ) - delimeter, 96, 128 );
SPR_Set( gHUD.GetSprite( m_HUD_health1 ), 255, 255, 255 );
SPR_DrawHoles( 0, x, y, 0 );
SPR_DisableScissor();
}
DrawDamage( flTime );

8
cl_dll/health.h

@ -110,6 +110,8 @@ public: @@ -110,6 +110,8 @@ public:
int m_iHealth;
int m_HUD_dmg_bio;
int m_HUD_cross;
int m_HUD_health1;
int m_HUD_health2;
float m_fAttackFront, m_fAttackRear, m_fAttackLeft, m_fAttackRight;
void GetPainColor( int &r, int &g, int &b );
float m_fFade;
@ -130,12 +132,6 @@ private: @@ -130,12 +132,6 @@ private:
void DrawPainRight();
void DrawDeathVision();
HSPRITE m_hSprite1;
HSPRITE m_hSprite2;
wrect_t *m_prc1;
wrect_t *m_prc2;
int m_iHeight; // width of the health innards
HSPRITE m_hPainFront;
HSPRITE m_hPainLeft;
HSPRITE m_hPainRight;

Loading…
Cancel
Save