From f47e7d1bce9b9a475c5b237e590ed935fd061d5e Mon Sep 17 00:00:00 2001 From: terencehill Date: Sat, 21 Mar 2020 15:12:05 +0100 Subject: [PATCH] Sync oxygen bar blinking with start drowning time --- qcsrc/client/hud/panel/healtharmor.qc | 2 +- qcsrc/client/miscfunctions.qc | 13 +++++++++++-- qcsrc/client/miscfunctions.qh | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/qcsrc/client/hud/panel/healtharmor.qc b/qcsrc/client/hud/panel/healtharmor.qc index 9523be0e5..1a61a96d3 100644 --- a/qcsrc/client/hud/panel/healtharmor.qc +++ b/qcsrc/client/hud/panel/healtharmor.qc @@ -84,7 +84,7 @@ void HUD_HealthArmor() float air_alpha = 1; if (STAT(AIR_FINISHED) && time > STAT(AIR_FINISHED)) { - air_alpha = blink(0.5, 0.5, 7); + air_alpha = blink_synced(0.5, 0.5, 7, STAT(AIR_FINISHED), -1); air_time = 10; } diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc index 2d0cf212d..d801ceabd 100644 --- a/qcsrc/client/miscfunctions.qc +++ b/qcsrc/client/miscfunctions.qc @@ -216,7 +216,11 @@ vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float b // NOTE base is the central value // freq: circle frequency, = 2*pi*frequency in hertz -float blink(float base, float range, float freq) +// start_pos: +// -1 start from the lower value +// 0 start from the base value +// 1 start from the higher value +float blink_synced(float base, float range, float freq, float start_time, int start_pos) { // note: // RMS = sqrt(base^2 + 0.5 * range^2) @@ -224,7 +228,12 @@ float blink(float base, float range, float freq) // base = sqrt(RMS^2 - 0.5 * range^2) // ensure RMS == 1 - return base + range * cos(time * freq); + return base + range * sin((time - start_time - (M_PI / 2) * start_pos) * freq); +} + +float blink(float base, float range, float freq) +{ + return blink_synced(base, range, freq, 0, 0); } void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag) diff --git a/qcsrc/client/miscfunctions.qh b/qcsrc/client/miscfunctions.qh index 56bb176ef..3397ab705 100644 --- a/qcsrc/client/miscfunctions.qh +++ b/qcsrc/client/miscfunctions.qh @@ -52,6 +52,7 @@ float expandingbox_sizefactor_from_fadelerp(float fadelerp); vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor); +float blink_synced(float base, float range, float freq, float start_time, int start_blink); float blink(float base, float range, float freq); void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag); -- 2.39.2