From be6b2259e2a150e6713d79574c2f64eaf7a25bd8 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 1 May 2013 14:27:39 +0200 Subject: [PATCH 4/4] Make the health bar gradually change from green to red --- prboom2/src/gl_intern.h | 2 +- prboom2/src/gl_main.c | 44 ++++++++++++++++------------------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git prboom2/src/gl_intern.h prboom2/src/gl_intern.h index b4be8d56..8c44d9a7 100644 --- prboom2/src/gl_intern.h +++ prboom2/src/gl_intern.h @@ -219,7 +219,7 @@ typedef struct typedef struct { - int cm; + float r,g; float x1, x2, x3; float z1, z2, z3; diff --git prboom2/src/gl_main.c prboom2/src/gl_main.c index 0a52a0b5..4f42ec46 100644 --- prboom2/src/gl_main.c +++ prboom2/src/gl_main.c @@ -2337,15 +2337,20 @@ static void gld_AddHealthBar(mobj_t* thing, GLSprite *sprite) GLHealthBar hbar; int health_percent = thing->health * 100 / thing->info->spawnhealth; - hbar.cm = -1; - if (health_percent <= health_bar_red) - hbar.cm = CR_RED; - else if (health_percent <= health_bar_yellow) - hbar.cm = CR_YELLOW; - else if (health_percent <= health_bar_green) - hbar.cm = CR_GREEN; + if (health_percent <= health_bar_red) { + hbar.r = 1; + hbar.g = 0; + } else if (health_percent <= health_bar_yellow) { + hbar.r = 1; + hbar.g = (double)(health_percent - health_bar_red) / + (health_bar_yellow - health_bar_red); + } else if (health_percent <= health_bar_green) { + /* FullSimplify[1-((percent-yellow)/(green-yellow))] */ + hbar.r = (double)(health_bar_green - health_percent) / + (health_bar_green - health_bar_yellow); + hbar.g = 1; + } - if (hbar.cm >= 0) { float sx2 = (float)thing->radius / 2.0f / MAP_SCALE; float sx1 = sx2 - (float)health_percent * (float)thing->radius / 100.0f / MAP_SCALE; @@ -2369,7 +2374,6 @@ static void gld_AddHealthBar(mobj_t* thing, GLSprite *sprite) static void gld_DrawHealthBars(void) { int i, count; - int cm = -1; count = gld_drawinfo.num_items[GLDIT_HBAR]; if (count > 0) @@ -2380,31 +2384,17 @@ static void gld_DrawHealthBars(void) for (i = count - 1; i >= 0; i--) { GLHealthBar *hbar = gld_drawinfo.items[GLDIT_HBAR][i].item.hbar; - if (hbar->cm != cm) - { - cm = hbar->cm; - glColor4f(cm2RGB[cm][0], cm2RGB[cm][1], cm2RGB[cm][2], 1.0f); - } + glColor4f(hbar->r, hbar->g, 0, 1); glVertex3f(hbar->x1, hbar->y, hbar->z1); glVertex3f(hbar->x2, hbar->y, hbar->z2); - } - glEnd(); - - if (health_bar_full_length) - { - glColor4f(0.5f, 0.5f, 0.5f, 1.0f); - glBegin(GL_LINES); - for (i = count - 1; i >= 0; i--) - { - GLHealthBar *hbar = gld_drawinfo.items[GLDIT_HBAR][i].item.hbar; - + if (health_bar_full_length) { + glColor4f(0.5f, 0.5f, 0.5f, 1.0f); glVertex3f(hbar->x1, hbar->y, hbar->z1); glVertex3f(hbar->x3, hbar->y, hbar->z3); } - glEnd(); } - + glEnd(); gld_EnableTexture2D(GL_TEXTURE0_ARB, true); } } -- 2.30.2