Added option to smoothly transition health bar display.

This commit is contained in:
Sebastian Zych 2020-08-04 20:51:47 +10:00
parent 6a3700345e
commit 2eeef3bdc0
4 changed files with 61 additions and 21 deletions

View file

@ -532,7 +532,7 @@ GAME_STATUS ControlPhase(int numFrames, int demoMode)
//SoundEffects(); //SoundEffects();
HealtBarTimer--; HealthBarTimer--;
GameTimer++; GameTimer++;
} }

View file

@ -6,6 +6,7 @@
#include "camera.h" #include "camera.h"
#include "level.h" #include "level.h"
#include "control.h" #include "control.h"
using namespace T5M::Renderer; using namespace T5M::Renderer;
short PickupX; short PickupX;
short PickupY; short PickupY;
@ -13,7 +14,9 @@ short CurrentPickup;
DISPLAY_PICKUP Pickups[MAX_COLLECTED_PICKUPS]; DISPLAY_PICKUP Pickups[MAX_COLLECTED_PICKUPS];
short PickupVel; short PickupVel;
int OldHitPoints = 1000; int OldHitPoints = 1000;
int HealtBarTimer = 40; int HealthBarTimer = 40;
float HealthBar = OldHitPoints;
float MutateAmount = 0;
int FlashState = 0; int FlashState = 0;
int FlashCount = 0; int FlashCount = 0;
int PoisonFlag = 0; int PoisonFlag = 0;
@ -22,6 +25,8 @@ extern RendererHUDBar* g_HealthBar;
extern RendererHUDBar* g_DashBar; extern RendererHUDBar* g_DashBar;
extern RendererHUDBar* g_AirBar; extern RendererHUDBar* g_AirBar;
bool EnableSmoothHealthBar = true;
void DrawHealthBarOverlay(int value) void DrawHealthBarOverlay(int value)
{ {
if (CurrentLevel) if (CurrentLevel)
@ -48,7 +53,7 @@ void DrawHealthBar(float value)
} }
} }
void UpdateHealtBar(int flash) void UpdateHealthBar(int flash)
{ {
int hitPoints = LaraItem->hitPoints; int hitPoints = LaraItem->hitPoints;
@ -57,44 +62,75 @@ void UpdateHealtBar(int flash)
else if (hitPoints > 1000) else if (hitPoints > 1000)
hitPoints = 1000; hitPoints = 1000;
// OPT: smoothly transition health bar display.
if (EnableSmoothHealthBar)
{
if (OldHitPoints != hitPoints)
{
MutateAmount += OldHitPoints - hitPoints;
OldHitPoints = hitPoints;
HealthBarTimer = 40;
}
if (HealthBar - MutateAmount < 0)
MutateAmount = HealthBar;
else if (HealthBar - MutateAmount > 1000)
MutateAmount = HealthBar - 1000;
HealthBar -= MutateAmount / 3;
MutateAmount -= MutateAmount / 3;
if (MutateAmount > -0.5f && MutateAmount < 0.5f)
{
MutateAmount = 0;
HealthBar = hitPoints;
}
}
// OG: discretely transition health bar display.
else
{
if (OldHitPoints != hitPoints) if (OldHitPoints != hitPoints)
{ {
OldHitPoints = hitPoints; OldHitPoints = hitPoints;
HealtBarTimer = 40; HealthBar = hitPoints;
HealthBarTimer = 40;
}
} }
if (HealtBarTimer < 0) if (HealthBarTimer < 0)
HealtBarTimer = 0; HealthBarTimer = 0;
if (hitPoints <= 1000 / 4) // Flash when at 1/4 capacity AND HP bar is not transitioning.
if (HealthBar <= 1000 / 4 && MutateAmount == 0)
{ {
if (!BinocularRange) if (!BinocularRange)
{ {
if (flash) if (flash)
DrawHealthBar(hitPoints / 1000.0f); DrawHealthBar(HealthBar / 1000.0f);
else else
DrawHealthBar(0); DrawHealthBar(0);
} }
else else
{ {
if (flash) if (flash)
DrawHealthBarOverlay(hitPoints / 1000.0f); DrawHealthBarOverlay(HealthBar / 1000.0f);
else else
DrawHealthBarOverlay(0); DrawHealthBarOverlay(0);
} }
} }
else if ((HealtBarTimer > 0) else if ((HealthBarTimer > 0)
|| (hitPoints <= 0) || (HealthBar <= 0)
|| (Lara.gunStatus == LG_READY && Lara.gunType != WEAPON_TORCH) || (Lara.gunStatus == LG_READY && Lara.gunType != WEAPON_TORCH)
|| (Lara.poisoned >= 256)) || (Lara.poisoned >= 256))
{ {
if (!BinocularRange && !SniperOverlay) if (!BinocularRange && !SniperOverlay)
{ {
DrawHealthBar(hitPoints / 1000.0f); DrawHealthBar(HealthBar / 1000.0f);
} }
else else
{ {
DrawHealthBarOverlay(hitPoints / 1000.0f); DrawHealthBarOverlay(HealthBar / 1000.0f);
} }
} }

View file

@ -9,7 +9,7 @@ typedef struct DISPLAY_PICKUP
void DrawHealthBarOverlay(int value); void DrawHealthBarOverlay(int value);
void DrawHealthBar(float value); void DrawHealthBar(float value);
void UpdateHealtBar(int flash); void UpdateHealthBar(int flash);
void DrawAirBar(float value); void DrawAirBar(float value);
void UpdateAirBar(int flash); void UpdateAirBar(int flash);
void DrawDashBar(int value); void DrawDashBar(int value);
@ -24,7 +24,11 @@ extern short CurrentPickup;
extern DISPLAY_PICKUP Pickups[MAX_COLLECTED_PICKUPS]; extern DISPLAY_PICKUP Pickups[MAX_COLLECTED_PICKUPS];
extern short PickupVel; extern short PickupVel;
extern int OldHitPoints; extern int OldHitPoints;
extern int HealtBarTimer; extern int HealthBarTimer;
extern float HealthBar;
extern float MutateAmount;
extern int FlashState; extern int FlashState;
extern int PoisonFlag; extern int PoisonFlag;
extern int DashTimer; extern int DashTimer;
extern bool EnableSmoothHealthBar;

View file

@ -2044,7 +2044,7 @@ namespace T5M::Renderer
int flash = FlashIt(); int flash = FlashIt();
if (DashTimer < 120) if (DashTimer < 120)
DrawBar(DashTimer / 120.0f, g_DashBar); DrawBar(DashTimer / 120.0f, g_DashBar);
UpdateHealtBar(flash); UpdateHealthBar(flash);
UpdateAirBar(flash); UpdateAirBar(flash);
DrawAllPickups(); DrawAllPickups();