push me to the edge
-
Автор темы
- #1
Ну решил я значит запилить себе рич хп бар, делюсь кодом
C++:
constexpr float SPEED_FREQ = 255 / 1.0f;
void CEsp::DrawHealthBar( C_CSPlayer* player, Rect2D bbox ) {
Color col_black = Color ( 0, 0, 0, static_cast< int > ( m_flAlpha[ player->entindex( ) ] ) );
int player_hp = player->m_iHealth( );
int player_hp_max = 100;
static float prev_player_hp[ 65 ];
if ( prev_player_hp[ player->entindex( ) ] > player_hp )
prev_player_hp[ player->entindex( ) ] -= SPEED_FREQ * Source::m_pGlobalVars->frametime;
else
prev_player_hp[ player->entindex( ) ] = player_hp;
float x = bbox.left - 10, float y = bbox.top, width = fabsf( bbox.bottom - bbox.top ) - ( ( ( fabsf( bbox.bottom - bbox.top ) * prev_player_hp[ player->entindex( ) ] ) / player_hp_max ) );
float w = 4, h = fabsf( bbox.bottom - bbox.top );
Color fill = Color ( static_cast< int > ( ( 130.0f - player_hp * 1.3f ) ), static_cast< int > ( ( player_hp * 2.55f ) ), 10, static_cast< int > ( ( m_flAlpha[ player->entindex( ) ] ) ) );
Color color = Color ( 255, 255, 255, static_cast< int > ( ( m_flAlpha[ player->entindex( ) ] * 0.85f ) ) );
Render::Get( )->SetTextFont( FONT_VISITOR );
Render::Get( )->AddRectFilled( Vector2D( x + 3, y - 1 ), Vector2D( x + w + 3, y + h + 1 ), Color ( 0.0f, 0.0f, 0.0f, m_flAlpha[ player->entindex( ) ] / 357.0f ) );
Render::Get( )->AddRectFilled( Vector2D( x + 4, y + width ), Vector2D( x + w - 1 + 3, y + h ), fill );
if ( player_hp != 100 )
Render::Get( )->AddText( Vector2D( x + 3, y + width + 1 ), color, OUTLINED | CENTER_X | CENTER_Y, "%d", player_hp );
}
Демонстрация работы
Пожалуйста, авторизуйтесь для просмотра ссылки.
Последнее редактирование: