engine-c: live HP always-on + thick selection rings + bld HP strip
This commit is contained in:
parent
76192f39b6
commit
3c7e953497
1 changed files with 32 additions and 18 deletions
|
|
@ -147,16 +147,20 @@ void render_buildings(Game *g) {
|
|||
SDL_RenderFillRect(g->ren, &(SDL_Rect){ sx + W - 10, sy + H - 5, 8, 5 });
|
||||
}
|
||||
}
|
||||
/* health bar if damaged or selected */
|
||||
if (b->hp < b->max_hp || b->selected) {
|
||||
SDL_Rect bar = { sx, sy - 6, W, 4 };
|
||||
SDL_SetRenderDrawColor(g->ren, 60, 60, 60, 255);
|
||||
SDL_RenderFillRect(g->ren, &bar);
|
||||
/* outlined HP strip (green→red) when damaged or selected */
|
||||
if (b->max_hp > 0 && (b->hp < b->max_hp * 0.95f || b->selected)) {
|
||||
int by = sy - 6;
|
||||
float f = b->hp / b->max_hp;
|
||||
SDL_Color c = (b->faction == FACTION_SURVIVOR) ? (SDL_Color){90,160,70,255}
|
||||
: (SDL_Color){170,70,180,255};
|
||||
SDL_Rect fill = { sx, sy - 6, (int)(W * f), 4 };
|
||||
SDL_SetRenderDrawColor(g->ren, c.r, c.g, c.b, 255);
|
||||
if (f < 0) f = 0; if (f > 1) f = 1;
|
||||
SDL_Rect outline = { sx - 1, by - 1, W + 2, 5 };
|
||||
SDL_SetRenderDrawColor(g->ren, 20, 18, 14, 255);
|
||||
SDL_RenderFillRect(g->ren, &outline);
|
||||
SDL_Rect bg = { sx, by, W, 3 };
|
||||
SDL_SetRenderDrawColor(g->ren, 55, 48, 36, 255);
|
||||
SDL_RenderFillRect(g->ren, &bg);
|
||||
Uint8 hr = (Uint8)(255 * (1.0f - f)), hg = (Uint8)(230 * f);
|
||||
SDL_Rect fill = { sx, by, (int)(W * f + 0.5f), 3 };
|
||||
SDL_SetRenderDrawColor(g->ren, hr, hg, 40, 255);
|
||||
SDL_RenderFillRect(g->ren, &fill);
|
||||
}
|
||||
if (b->selected) {
|
||||
|
|
@ -220,6 +224,21 @@ static void draw_unit_shadow(SDL_Renderer *ren, int cx, int cy, int rad) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Filled annulus selection ring (parity with snapshot ring t≈2). */
|
||||
static void draw_sel_ring(SDL_Renderer *ren, int cx, int cy, int rad, int t) {
|
||||
int inner = rad - t;
|
||||
if (inner < 0) inner = 0;
|
||||
int r2 = rad * rad, i2 = inner * inner;
|
||||
SDL_SetRenderDrawColor(ren, 255, 245, 60, 220);
|
||||
for (int y = -rad; y <= rad; y++) {
|
||||
for (int x = -rad; x <= rad; x++) {
|
||||
int d = x * x + y * y;
|
||||
if (d <= r2 && d >= i2)
|
||||
SDL_RenderDrawPoint(ren, cx + x, cy + y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int live_unit_wheeled(UnitType t) {
|
||||
return t == UT_BUGGY || t == UT_JEEP || t == UT_HARVESTER
|
||||
|| t == UT_BEAST || t == UT_MISSILE || t == UT_MEDIC;
|
||||
|
|
@ -328,19 +347,14 @@ void render_units(Game *g) {
|
|||
SDL_SetRenderDrawColor(g->ren, 255, 250, 220, 220);
|
||||
SDL_RenderDrawLine(g->ren, cx + 1, cy, hx + 1, hy);
|
||||
}
|
||||
/* selection ring — larger for heavy chassis */
|
||||
/* thick selection annulus (parity with snapshot ring t=2) */
|
||||
if (u->selected) {
|
||||
int rad = (u->type == UT_TANK || u->type == UT_BEAST || u->type == UT_RAVAGER)
|
||||
? sz / 2 + 4 : sz / 2 + 2;
|
||||
SDL_SetRenderDrawColor(g->ren, 255, 245, 60, 220);
|
||||
for (int a = 0; a < 360; a += 10) {
|
||||
int px = cx + (int)(cosf(a * 3.14159f / 180) * rad);
|
||||
int py = cy + (int)(sinf(a * 3.14159f / 180) * rad);
|
||||
SDL_RenderDrawPoint(g->ren, px, py);
|
||||
}
|
||||
draw_sel_ring(g->ren, cx, cy, rad, 2);
|
||||
}
|
||||
/* HP bar: green→red strip like snapshot */
|
||||
if (u->hp < u->max_hp || u->selected) {
|
||||
/* always-on HP bar when max_hp known (parity with snapshot) */
|
||||
if (u->max_hp > 0) {
|
||||
int by = cy - sz / 2 - 8;
|
||||
int bw = sz - 6;
|
||||
if (bw < 24) bw = 24;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue