Вопрос Как нарисовать HP Bar во всех 4 случаях?

Начинающий
Статус
Оффлайн
Регистрация
22 Дек 2018
Сообщения
360
Реакции[?]
21
Поинты[?]
0
Всем здравствуйте.

Мне нужна помощь с отрисовкой HP Bar.
Помогите показать и рассказать и объяснить на примере картинки и моего кода, как отросовывать Hp Bar во всех 4 случаях(Слева, сверху, справа, снизу).
Мне это нужно для понимания как с таким работать.

Rect.left or right and etc.. у меня вызывается с помощью функции BBox, код которого на фото внизу.

Код HP Bar Слева и справа:
Hp Bar LEFT & RIGHT:
CVector2 pos(int(rect.left) - 7, int(rect.top) + 1);
CVector2 size(1.f, (-std::abs(int(rect.bottom - rect.top)) * delta) - 2.f);

CVector2 pos_right(int(rect.right) - 7, int(rect.top) + 1);
CVector2 size_right(1.f, (-std::abs(int(rect.bottom - rect.top)) * delta) - 2.f);

switch (HpType)
{
    case 1: // left
    {
        DrawSimpleBox(pos, size, CColor(red, green, 0)); // Сама полоска здоровья
        g_pRender->DrawRect(CVector2(int(rect.left) - 8, int(rect.top) + 1), CVector2(3, int(rect.bottom - rect.top) - 2), CColor(0, 0, 0)); // Обводка
        break;
    }
    case 2: // bottom
    {
        ?
        ?
        break;
    }
    case 3: // top
        ?
        ?
        break;
    case 4: // right
        DrawSimpleBox(pos_right, size_right, CColor(red, green, 0)); // Сама полоска здоровья
        g_pRender->DrawRect(CVector2(int(rect.left) - 8, int(rect.top) + 1), CVector2(3, int(rect.bottom - rect.top) - 2), CColor(0, 0, 0)); // Обводка
        break;
}
P.S. Там где вопросы я не знаю что писать.

Так же если нужно вот код самого BBOX()
1674652494903.png
 
Эксперт
Статус
Оффлайн
Регистрация
30 Дек 2019
Сообщения
1,970
Реакции[?]
958
Поинты[?]
19K
C++:
switch ( render_pos ) {
    case e_position::pos_bottom:
        size = { w, m_bar_size };
        pos = { 0.f, h + m_padding + current_offset };
        horizontal = true;
        break;
    case e_position::pos_top:
        size = { w, m_bar_size };
        pos = { 0.f, -m_padding - m_bar_size - current_offset };
        horizontal = true;
        break;
    case e_position::pos_left:
        size = { m_bar_size, h };
        pos = { -m_padding - m_bar_size - current_offset, 0.f };
        break;
    case e_position::pos_right:
        size = { m_bar_size, h };
        pos = { w + m_padding + current_offset, 0.f };
        break;
    default:
        return;
}
        
float bar_fill = std::clamp( value / max, 0.f, 1.f );
if ( horizontal ) {
    render::rect_filled( vec2_t( x + pos.x, y + pos.y - 1 ), vec2_t( size.x, size.y + 2 ), color_t( 35, 35, 35, ( uint8_t ) ( 255 * m_alpha ) ) );

    pos.x += 1;
    size.x -= 2;

    render::rect_filled( vec2_t( x + pos.x, y + pos.y ), vec2_t( size.x * bar_fill, size.y ), color.override_alpha( ( uint8_t ) ( 255.f * m_alpha ) ) );
    if ( show_text && ( int )value < ( int )max )
        render::text( std::to_string( ( int ) value ), vec2_t( x + pos.x + size.x * bar_fill, y + pos.y ), color_t( 255, 255, 255, ( uint8_t ) ( 255.f * m_alpha ) ), render::fonts::verdana_11, font_outline );
}
else {
    render::rect_filled( vec2_t( x + pos.x - 1, y + pos.y ), vec2_t( size.x + 2, size.y ), color_t( 35, 35, 35, ( uint8_t ) ( 255.f * m_alpha ) ) );

    pos.y += 1;
    size.y -= 2;
    
    render::rect_filled( vec2_t( x + pos.x, y + pos.y + size.y * ( 1.f - bar_fill ) ), vec2_t( size.x, size.y * bar_fill ), color.override_alpha( ( uint8_t ) ( 255.f * m_alpha ) ), 0.f );
    if ( show_text && ( int ) value < ( int ) max )
        render::text( std::to_string( ( int ) value ), vec2_t( x + pos.x, y + pos.y + size.y * ( 1.f - bar_fill ) ), color_t( 255, 255, 255, ( uint8_t ) ( 255.f * m_alpha ) ), render::fonts::verdana_11, font_outline | font_centered );
}
 
Начинающий
Статус
Оффлайн
Регистрация
22 Дек 2018
Сообщения
360
Реакции[?]
21
Поинты[?]
0
C++:
switch ( render_pos ) {
    case e_position::pos_bottom:
        size = { w, m_bar_size };
        pos = { 0.f, h + m_padding + current_offset };
        horizontal = true;
        break;
    case e_position::pos_top:
        size = { w, m_bar_size };
        pos = { 0.f, -m_padding - m_bar_size - current_offset };
        horizontal = true;
        break;
    case e_position::pos_left:
        size = { m_bar_size, h };
        pos = { -m_padding - m_bar_size - current_offset, 0.f };
        break;
    case e_position::pos_right:
        size = { m_bar_size, h };
        pos = { w + m_padding + current_offset, 0.f };
        break;
    default:
        return;
}
       
float bar_fill = std::clamp( value / max, 0.f, 1.f );
if ( horizontal ) {
    render::rect_filled( vec2_t( x + pos.x, y + pos.y - 1 ), vec2_t( size.x, size.y + 2 ), color_t( 35, 35, 35, ( uint8_t ) ( 255 * m_alpha ) ) );

    pos.x += 1;
    size.x -= 2;

    render::rect_filled( vec2_t( x + pos.x, y + pos.y ), vec2_t( size.x * bar_fill, size.y ), color.override_alpha( ( uint8_t ) ( 255.f * m_alpha ) ) );
    if ( show_text && ( int )value < ( int )max )
        render::text( std::to_string( ( int ) value ), vec2_t( x + pos.x + size.x * bar_fill, y + pos.y ), color_t( 255, 255, 255, ( uint8_t ) ( 255.f * m_alpha ) ), render::fonts::verdana_11, font_outline );
}
else {
    render::rect_filled( vec2_t( x + pos.x - 1, y + pos.y ), vec2_t( size.x + 2, size.y ), color_t( 35, 35, 35, ( uint8_t ) ( 255.f * m_alpha ) ) );

    pos.y += 1;
    size.y -= 2;
   
    render::rect_filled( vec2_t( x + pos.x, y + pos.y + size.y * ( 1.f - bar_fill ) ), vec2_t( size.x, size.y * bar_fill ), color.override_alpha( ( uint8_t ) ( 255.f * m_alpha ) ), 0.f );
    if ( show_text && ( int ) value < ( int ) max )
        render::text( std::to_string( ( int ) value ), vec2_t( x + pos.x, y + pos.y + size.y * ( 1.f - bar_fill ) ), color_t( 255, 255, 255, ( uint8_t ) ( 255.f * m_alpha ) ), render::fonts::verdana_11, font_outline | font_centered );
}
Не понимаю, мог бы ты помочь на моем примере объяснить пожалуйста?
 
Начинающий
Статус
Оффлайн
Регистрация
25 Окт 2022
Сообщения
35
Реакции[?]
6
Поинты[?]
0
Не понимаю, мог бы ты помочь на моем примере объяснить пожалуйста?
Я кнш таким же был, но тут отличный пример. Тебе надо вставить этот код и сделать аналогично. В чем проблема ? Или тебе нужно чтоб все расписали и покормили с ложечки ?
 
Начинающий
Статус
Оффлайн
Регистрация
22 Дек 2018
Сообщения
360
Реакции[?]
21
Поинты[?]
0
Я кнш таким же был, но тут отличный пример. Тебе надо вставить этот код и сделать аналогично. В чем проблема ? Или тебе нужно чтоб все расписали и покормили с ложечки ?
Мне нужен было что бы просто объяснили на примере моего кода как работает всё это, и как в разных случая по разному разместить hp bar.

я уже понял как, информацию почитал, тема закрыта.
Всем спасибо кто подсказывал
 
Сверху Снизу