Implement score increase/decrease accumulator in HUD.

This commit is contained in:
Mari the Deer 2024-07-18 14:22:35 +02:00
commit 68c01dbd63
5 changed files with 81 additions and 3 deletions

View file

@ -171,6 +171,24 @@ extend Class SWWMHandler
// send the post-teleport position
DoPlayerStep(demo.pos.xy,true);
}
else if ( e.Name ~== "swwmhudgivescore" )
{
let bar = SWWMStatusBar(StatusBar);
if ( !bar ) return;
if ( bar.cummscoreup+e.Args[0] < bar.cummscoreup ) bar.cummscoreup = 999999999;
else bar.cummscoreup = min(999999999,bar.cummscoreup+e.Args[0]);
bar.cummspanup = 120+40*int(Log10(clamp(bar.cummscoreup,1,999999999)));
bar.cummflashup = 15;
}
else if ( e.Name ~== "swwmhudtakescore" )
{
let bar = SWWMStatusBar(StatusBar);
if ( !bar ) return;
if ( bar.cummscoredn+e.Args[0] < bar.cummscoredn ) bar.cummscoredn = 999999999;
else bar.cummscoredn = min(999999999,bar.cummscoredn+e.Args[0]);
bar.cummspandn = 120+40*int(Log10(clamp(bar.cummscoredn,1,999999999)));
bar.cummflashdn = 15;
}
}
override void NetworkProcess( ConsoleEvent e )

View file

@ -197,6 +197,10 @@ Class SWWMStatusBar : BaseStatusBar
SmoothDynamicValueInterpolator HealthInter, FuelInter, DashInter;
SmoothLinearValueInterpolator LagHealthInter;
// please do not misread
int cummscoreup, cummspanup, cummflashup;
int cummscoredn, cummspandn, cummflashdn;
transient ui int rss;
// called by static handler when loading a game

View file

@ -52,6 +52,19 @@ extend Class SWWMStatusBar
if ( !(i is 'SWWMWeapon') ) continue;
SWWMWeapon(i).HudTick();
}
// score accumulator
if ( cummflashup > 0 ) cummflashup--;
if ( cummflashdn > 0 ) cummflashdn--;
if ( cummspanup > 0 )
{
cummspanup--;
if ( cummspanup <= 0 ) cummscoreup = 0;
}
if ( cummspandn > 0 )
{
cummspandn--;
if ( cummspandn <= 0 ) cummscoredn = 0;
}
}
// hello??? why is this function clearscope???
@ -256,6 +269,35 @@ extend Class SWWMStatusBar
yy += 2;
for ( int i=0; i<dcnt; i++ ) Screen.DrawChar(MiniHUDFont,mhudfontcol[MCR_BRASS],xx+i*4,yy,0x30,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_ColorOverlay,Color(160,0,0,0));
Screen.DrawText(MiniHUDFont,mhudfontcol[MCR_BRASS],xx,yy,sstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
// accumulator (for local player only)
xx -= 4;
yy--;
if ( cummscoreup && (CPlayer == players[consoleplayer]) )
{
yy -= 8;
double calph = clamp(cummspanup-fractic,0.,20.)/20.;
sstr = String.Format("%+10d",min(cummscoreup,999999999));
Screen.DrawText(MiniHUDFontOutline,mhudfontcol[MCR_BRASS],xx,yy,sstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,calph);
if ( cummflashup > 0 )
{
double falph = max((cummflashup-FracTic)/15.,0.)**1.5;
Screen.DrawText(MiniHUDFontOutline,mhudfontcol[MCR_FLASH],xx,yy,sstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,falph*calph,DTA_LegacyRenderStyle,STYLE_Add);
}
// smooth fade offset for next line
yy += (1.-calph)*8;
}
if ( cummscoredn && (CPlayer == players[consoleplayer]) )
{
yy -= 8;
double calph = clamp(cummspandn-fractic,0.,20.)/20.;
sstr = String.Format("%+10d",-min(cummscoredn,999999999));
Screen.DrawText(MiniHUDFontOutline,mhudfontcol[MCR_RED],xx,yy,sstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,calph);
if ( cummflashdn > 0 )
{
double falph = max((cummflashdn-FracTic)/15.,0.)**1.5;
Screen.DrawText(MiniHUDFontOutline,mhudfontcol[MCR_REDFLASH],xx,yy,sstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,falph*calph,DTA_LegacyRenderStyle,STYLE_Add);
}
}
int bx = bDrewAmmo?56:50;
// ammo display
if ( CPlayer.ReadyWeapon is 'SWWMWeapon' ) SWWMWeapon(CPlayer.ReadyWeapon).DrawWeapon(FracTic,ss.x-(xmargin+bx),ss.y-(ymargin+12),hs,ss);

View file

@ -385,6 +385,13 @@ Class SWWMCredits : SWWMStaticThinker
else c.credits = min(999999999,c.credits+amount);
let s = SWWMStats.Find(p);
if ( s && (c.credits > s.hiscore) ) s.hiscore = c.credits;
// append to hud
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( players[i] != p ) continue;
EventHandler.SendInterfaceEvent(i,"swwmhudgivescore",amount);
break;
}
SWWMLoreLibrary.Add(p,"ScoreSystem");
}
@ -399,7 +406,7 @@ Class SWWMCredits : SWWMStaticThinker
return true;
}
static bool Take( PlayerInfo p, int amount, int hamount = 0 )
static bool Take( PlayerInfo p, int amount )
{
let c = Find(p);
if ( !c ) return false;
@ -408,6 +415,13 @@ Class SWWMCredits : SWWMStaticThinker
// too much!
if ( (amount > 999999999) || (c.credits-amount < 0) || (c.credits-amount > c.credits) ) return false;
c.credits -= amount;
// append to hud
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( players[i] != p ) continue;
EventHandler.SendInterfaceEvent(i,"swwmhudtakescore",amount);
break;
}
return true;
}