Skip to content

Commit

Permalink
Improve crosshair health display
Browse files Browse the repository at this point in the history
The new implementation has numerous upsides compared to the
previous implementation:

- It indicates the player's health more accurately using a
  color gradient well-known among FPS players. Health above 100
  is indicated by tinting the crosshair green.
- It's always visible, even in screenshots. Due to lack of animation,
  it also avoids hiding the health status on every
  loop of the animation (since the crosshair became white).

The variable was renamed from `crosshairflash` to `crosshairhealth`
to reflect the change.
  • Loading branch information
Calinou committed Dec 29, 2019
1 parent 06f3161 commit 27a2df8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/usage.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ setdesc "crosshairsize" "size of crosshair (in terms of screen size)" "value"
setdesc "crosshairhitspeed" "duration for hit crosshair to show following a hit on an opponent (milliseconds)" "value"
setdesc "crosshairblend" "determines crosshair opacity (0 = transparent 1 = opaque)" "value"
setdesc "crosshairaccamt" "determines blend by accuracy level intensity (when blend by accuracy is enabled)" "value"
setdesc "crosshairflash" "determines whether the crosshair flashes when at critical health (less than the heal amount)" "value"
setdesc "crosshairhealth" "determines whether to color the crosshair depending on the current health" "value"
setdesc "crosshairthrob" "determines scale of crosshair throb (size change) effect (like while gaining health)" "value"
setdesc "crosshairtex" "determines path to crosshair image file" "file"
setdesc "showfps" "display the frames per second counter on the hud;^n0 = no display^n1 = display average fps^n2 = display average fps and best and worst difference^n3 = display average fps and fps range^n4 = display average fps and average/worst frametimes" "value"
Expand Down
35 changes: 31 additions & 4 deletions src/game/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,11 +1174,38 @@ namespace hud
else if(crosshairweapons&2) c = vec::fromcolor(W(game::focus->weapselect, colour));
else if(crosshairtone) skewcolour(c.r, c.g, c.b, crosshairtone);
int heal = game::focus->gethealth(game::gamemode, game::mutators);
if(crosshairflash && game::focus->state == CS_ALIVE && game::focus->health < heal)
if(crosshairflash && game::focus->state == CS_ALIVE)
{
int millis = lastmillis%1000;
float amt = (millis <= 500 ? millis/500.f : 1.f-((millis-500)/500.f))*clamp(float(heal-game::focus->health)/float(heal), 0.f, 1.f);
flashcolour(c.r, c.g, c.b, 1.f, 0.f, 0.f, amt);
const float ratio = clamp(float(game::focus->health)/float(heal), 0.0f, 2.0f);

if(ratio < 0.2f)
{
// Red (critical health level)
c.r = 1.0f;
c.g = 0.0f;
c.b = 0.0f;
}
else if(ratio < 0.6f)
{
// Red-yellow
c.r = 1.0f;
c.g = (ratio-0.2f)/0.4f;
c.b = 0.0f;
}
else if(ratio < 1.0f)
{
// Yellow-white
c.r = 1.0f;
c.g = 1.0f;
c.b = (ratio-0.6f)/0.4f;
}
else
{
// Green (overheal)
c.r = 2.0f - ratio;
c.g = 1.0f;
c.b = 2.0f - ratio;
}
}
if(crosshairthrob > 0 && regentime && game::focus->lastregen && lastmillis-game::focus->lastregen <= regentime)
{
Expand Down

0 comments on commit 27a2df8

Please sign in to comment.