Skip to content

Commit

Permalink
CLIENT: Revamp Max Ammo! HUD animation
Browse files Browse the repository at this point in the history
  • Loading branch information
MotoLegacy committed May 19, 2024
1 parent 78c7f70 commit 32f1534
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
6 changes: 2 additions & 4 deletions source/client/defs/custom.qc
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ float useprint_time;

float bettyprompt_time;

string scrolltext;
float stext;
float scrollopacity;
float scrollheight;
float hud_maxammo_endtime;
float hud_maxammo_starttime;

float nameprint_time;
float HUD_Change_time;
Expand Down
60 changes: 42 additions & 18 deletions source/client/hud.qc
Original file line number Diff line number Diff line change
Expand Up @@ -1562,19 +1562,47 @@ void() HUD_Screenflash =
drawfill ([0, 0], [g_width, g_height, 0], color, flash_alpha, 0);
}

void(float width, float height) HUD_ScrollText = {
float print_width = stringwidth (scrolltext, 0, [12, 12, 0]);
float x = (width - print_width)/2;

drawstring([x, scrollheight*height, 0], scrolltext, [12, 12, 0], [1, 1, 1], scrollopacity, 0); //low
if (scrollheight > 0.70) {
scrollheight -= frametime/10;
if (scrollopacity > 0)
scrollopacity -= frametime;
} else {
stext = 0;
//
// HUD_MaxAmmo(width, height)
// Displays the "Max Ammo!" text on the HUD.
//
void(float width, float height) HUD_MaxAmmo =
{
string maxammo_string = "Max Ammo!";

float start_y = 70;
float end_y = 55;
float diff_y = end_y - start_y;

float text_alpha = 1;

float string_width = stringwidth(maxammo_string, 0, [14, 14]);
float pos_x = (width - string_width)/2;
float pos_y;

float start_time, end_time;

// For the first 0.5s, stay still while we fade in
if (hud_maxammo_endtime > time + 1.5) {
start_time = hud_maxammo_starttime;
end_time = hud_maxammo_starttime + 0.5;

text_alpha = (time - start_time) / (end_time - start_time);
pos_y = start_y;
}
}
// For the remaining 1.5s, fade out while we fly upwards.
else {
start_time = hud_maxammo_starttime + 0.5;
end_time = hud_maxammo_endtime;

float percent_time = (time - start_time) / (end_time - start_time);

pos_y = start_y + diff_y * percent_time;
text_alpha = 1 - percent_time;
}

drawstring([pos_x, pos_y, 0], maxammo_string, [14, 14], [1, 1, 1], text_alpha, 0);
};

float achievement_init;
float achievement_ypos;
Expand Down Expand Up @@ -1803,12 +1831,8 @@ void(float width, float height) HUD_Draw =
if (Hitmark_time > time)
HUD_Hitmark();

if (stext) {
HUD_ScrollText(width, height);
} else {
scrollopacity = 1;
scrollheight = 0.80;
}
if (hud_maxammo_endtime > time)
HUD_MaxAmmo(width, height);

HUD_PlayerNames(width, height);
HUD_ReviveIcons(width, height);
Expand Down
4 changes: 2 additions & 2 deletions source/client/main.qc
Original file line number Diff line number Diff line change
Expand Up @@ -982,8 +982,8 @@ noref void() CSQC_Parse_Event =
broadcast_num = readbyte();
break;
case CSQC_EVENT_MAXAMMOTEXT:
scrolltext = "MAX AMMO!";
stext = true;
hud_maxammo_endtime = time + 2;
hud_maxammo_starttime = time;
break;
case CSQC_EVENT_MUSICSTREAM:
string track_name = readstring();
Expand Down

0 comments on commit 32f1534

Please sign in to comment.