Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve crosshair health color to be more informative
With `crosshairhealth 2`, the crosshair will now
go from white to yellow, then yellow to red as the player's health
decreases. As the player's health increases up to 200, the crosshair
will also go from white to green to indicate overheal.
This is similar to the implementation in games like Xonotic.

The old behavior (`crosshairhealth 1`) is still the default.
  • Loading branch information
Calinou authored and coelckers committed Aug 18, 2019
1 parent 94179a1 commit 61badfd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
52 changes: 48 additions & 4 deletions src/g_statusbar/shared_sbar.cpp
Expand Up @@ -128,7 +128,7 @@ CVAR (Bool, crosshairon, true, CVAR_ARCHIVE);
CVAR (Int, crosshair, 0, CVAR_ARCHIVE)
CVAR (Bool, crosshairforce, false, CVAR_ARCHIVE)
CVAR (Color, crosshaircolor, 0xff0000, CVAR_ARCHIVE);
CVAR (Bool, crosshairhealth, true, CVAR_ARCHIVE);
CVAR (Int, crosshairhealth, 1, CVAR_ARCHIVE);
CVAR (Float, crosshairscale, 1.0, CVAR_ARCHIVE);
CVAR (Bool, crosshairgrow, false, CVAR_ARCHIVE);
CUSTOM_CVAR(Int, am_showmaplabel, 2, CVAR_ARCHIVE)
Expand Down Expand Up @@ -1081,15 +1081,15 @@ void DBaseStatusBar::DrawCrosshair ()
w = int(CrosshairImage->GetDisplayWidth() * size);
h = int(CrosshairImage->GetDisplayHeight() * size);

if (crosshairhealth)
{
if (crosshairhealth == 1) {
// "Standard" crosshair health (green-red)
int health = Scale(CPlayer->health, 100, CPlayer->mo->GetDefault()->health);

if (health >= 85)
{
color = 0x00ff00;
}
else
else
{
int red, green;
health -= 25;
Expand All @@ -1110,6 +1110,50 @@ void DBaseStatusBar::DrawCrosshair ()
color = (red<<16) | (green<<8);
}
}
else if (crosshairhealth == 2)
{
// "Enhanced" crosshair health (green-white-yellow-red)
int health = Scale(CPlayer->health, 100, CPlayer->mo->GetDefault()->health);
int red, green, blue;

if (health < 0)
{
health = 0;
}

if (health <= 25)
{
red = 255;
green = 0;
blue = 0;
}
else if (health <= 65)
{
red = 255;
green = 255 * ((health - 25) / 40.0);
blue = 0;
}
else if (health <= 100)
{
red = 255;
green = 255;
blue = 255 * ((health - 65) / 35.0);
}
else if (health < 200)
{
red = 255 - 255 * ((health - 100) / 100.0);
green = 255;
blue = 255 - 255 * ((health - 100) / 100.0);
}
else
{
red = 0;
green = 255;
blue = 0;
}

color = (red<<16) | (green<<8) | blue;
}
else
{
color = crosshaircolor;
Expand Down
9 changes: 8 additions & 1 deletion wadsrc/static/menudef.txt
Expand Up @@ -948,6 +948,13 @@ OptionMenu "VideoOptions" protected
//
//-------------------------------------------------------------------------------------------

OptionValue CrosshairHealthTypes
{
0.0, "$OPTVAL_NO"
1.0, "$OPTVAL_YES_STANDARD"
2.0, "$OPTVAL_YES_ENHANCED"
}

OptionValue DisplayTagsTypes
{
0.0, "$OPTVAL_NONE"
Expand Down Expand Up @@ -1017,7 +1024,7 @@ OptionMenu "HUDOptions" protected
Option "$HUDMNU_FORCECROSSHAIR", "crosshairforce", "OnOff"
Option "$HUDMNU_GROWCROSSHAIR", "crosshairgrow", "OnOff"
ColorPicker "$HUDMNU_CROSSHAIRCOLOR", "crosshaircolor"
Option "$HUDMNU_CROSSHAIRHEALTH", "crosshairhealth", "OnOff"
Option "$HUDMNU_CROSSHAIRHEALTH", "crosshairhealth", "CrosshairHealthTypes"
Slider "$HUDMNU_CROSSHAIRSCALE", "crosshairscale", 0.0, 2.0, 0.05, 2
StaticText " "
Option "$HUDMNU_NAMETAGS", "displaynametags", "DisplayTagsTypes"
Expand Down

0 comments on commit 61badfd

Please sign in to comment.