forked from pool/prboom-plus
Jan Engelhardt
81ac4d4360
OBS-URL: https://build.opensuse.org/package/show/games/prboom-plus?expand=0&rev=40
86 lines
2.7 KiB
Diff
86 lines
2.7 KiB
Diff
From be1128c66a342ca381532ac3c6bcd286d871fdc3 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 763bcbae..8dcb03fd 100644
|
|
--- prboom2/src/gl_main.c
|
|
+++ prboom2/src/gl_main.c
|
|
@@ -2340,16 +2340,24 @@ static void gld_AddHealthBar(mobj_t* thing, GLSprite *sprite)
|
|
{
|
|
GLHealthBar hbar;
|
|
int health_percent = thing->health * 100 / thing->info->spawnhealth;
|
|
+ int yr = health_bar_yellow - health_bar_red;
|
|
|
|
- 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 = yr == 0 ? 0 : (float)health_percent / yr;
|
|
+ } else if (health_percent <= health_bar_yellow) {
|
|
+ hbar.r = yr == 0 ? 1 : (float)(health_bar_yellow - health_percent) / yr;
|
|
+ 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 && hbar.g >= 0)
|
|
{
|
|
float sx2 = (float)thing->radius / 2.0f / MAP_SCALE;
|
|
float sx1 = sx2 - (float)health_percent * (float)thing->radius / 100.0f / MAP_SCALE;
|
|
@@ -2373,7 +2381,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)
|
|
@@ -2384,11 +2391,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
|
|
|