85 lines
2.7 KiB
Diff
85 lines
2.7 KiB
Diff
From 6566b0489164957581d091119bdf480d66e9ca20 Mon Sep 17 00:00:00 2001
|
|
From: Jan Engelhardt <jengelh@inai.de>
|
|
Date: Wed, 1 May 2013 09:53:49 +0200
|
|
Subject: [PATCH 2/2] Implement color gradient for health bar
|
|
References: https://github.com/coelckers/prboom-plus/pull/274
|
|
|
|
---
|
|
prboom2/src/gl_intern.h | 2 +-
|
|
prboom2/src/gl_main.c | 31 +++++++++++++++++--------------
|
|
2 files changed, 18 insertions(+), 15 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 e2402e16..0a257ecf 100644
|
|
--- prboom2/src/gl_main.c
|
|
+++ prboom2/src/gl_main.c
|
|
@@ -2334,15 +2334,23 @@ 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;
|
|
+ hbar.r = hbar.g = -1.0f;
|
|
+ if (health_percent <= 0) {
|
|
+ hbar.r = 1.0f;
|
|
+ hbar.g = 0.0f;
|
|
+ } else if (health_percent <= health_bar_red) {
|
|
+ hbar.r = 1.0f;
|
|
+ hbar.g = (double)health_percent / (health_bar_yellow - health_bar_red);
|
|
+ } else if (health_percent <= health_bar_yellow) {
|
|
+ hbar.r = (double)(health_bar_yellow - health_percent) /
|
|
+ (health_bar_yellow - health_bar_red);
|
|
+ hbar.g = 1.0f;
|
|
+ } else if (health_percent <= health_bar_green) {
|
|
+ hbar.r = 0.0f;
|
|
+ hbar.g = 1.0f;
|
|
+ }
|
|
|
|
- if (hbar.cm >= 0)
|
|
+ if (hbar.r >= 0)
|
|
{
|
|
float sx2 = (float)thing->radius / 2.0f / MAP_SCALE;
|
|
float sx1 = sx2 - (float)health_percent * (float)thing->radius / 100.0f / MAP_SCALE;
|
|
@@ -2366,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)
|
|
@@ -2377,11 +2384,7 @@ 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.0f, 1.0f);
|
|
|
|
glVertex3f(hbar->x1, hbar->y, hbar->z1);
|
|
glVertex3f(hbar->x2, hbar->y, hbar->z2);
|
|
--
|
|
2.31.1
|
|
|