]> git.xolatile.top Git - xolatile-badassbug.git/commitdiff
Speedometer game script variables...
authorxolatile <xolatile@proton.me>
Thu, 24 Jul 2025 23:47:52 +0000 (01:47 +0200)
committerxolatile <xolatile@proton.me>
Thu, 24 Jul 2025 23:47:52 +0000 (01:47 +0200)
src/fpsgame/fps.cpp
src/fpsgame/game.h

index 038fe47f1a7b669395fe5142bf0c4d7d327e1b1a..885bb3af01d78a58272d3c533f7d2e5e085a8ed5 100644 (file)
@@ -872,16 +872,50 @@ namespace game
         pophudmatrix();
     }
 
+    VARP(speedometer, 0, 1, 1);
+    FVARP(speedometerx, 0.0, 0.5, 1.0);
+    FVARP(speedometery, 0.0, 0.6, 1.0);
+    FVARP(speedometerscale, 0.1, 0.5, 2.0);
+    VARP(speedometercolor, 0, 1, 1);
+    FVARP(speedometeralpha, 0.0, 0.5, 1.0);
+
+    //~void drawspeedometer(fpsent *d, int w, int h) {
+        //~int speedforreal = (int) (sqrtf(d->vel.squaredlen()) + 1.0f);
+        //~speedforreal = (speedforreal == 1) ? 0 : speedforreal;
+        //~vec colour = vec(255, 255, 255);
+        //~float realw = 0;
+        //~float realh = 0;
+        //~if (speedometercolor) {
+            //~if (speedforreal==0)                            colour = vec(60, 60, 60);
+            //~else if (speedforreal>0   && speedforreal<=60)  colour = vec(240, 30, 30);
+            //~else if (speedforreal>60  && speedforreal<=120) colour = vec(180, 90, 60);
+            //~else if (speedforreal>120 && speedforreal<=180) colour = vec(180, 180, 30);
+            //~else if (speedforreal>180 && speedforreal<=240) colour = vec(90, 180, 60);
+            //~else                                            colour = vec(30, 240, 30);
+        //~}
+
+        //~defformatstring(speedstring, "%d", speedforreal);
+        //~text_boundsf(speedstring, realw, realh);
+        //~vec2 offset = vec2(speedometerx, speedometery).mul(vec2(w, h).div(speedometerscale));
+        //~offset.x -= realw/2.0f;
+        //~offset.y -= realh/2.0f;
+
+        //~pushhudmatrix();
+        //~hudmatrix.scale(speedometerscale, speedometerscale, 1);
+        //~flushhudmatrix();
+
+        //~draw_text(speedstring, int(offset.x), int(offset.y), colour.x, colour.y, colour.z, speedometeralpha);
+
+        //~pophudmatrix();
+    //~}
+
     VARP(healthcolors, 0, 1, 1);
 
     void drawhudicons(fpsent *d)
     {
-        int speedforreal = (int) (sqrtf(d->vel.squaredlen()) + /*speedmodifier*/ + 1.0f);
-
         pushhudmatrix();
         hudmatrix.scale(2, 2, 1);
         flushhudmatrix();
-
         defformatstring(health, "%d", d->state==CS_DEAD ? 0 : d->health);
         bvec healthcolor = bvec::hexcolor(healthcolors && !m_insta ? (d->state==CS_DEAD ? 0x808080 : (d->health<=25 ? 0xFF0000 : (d->health<=50 ? 0xFF8000 : (d->health<=100 ? 0xFFFFFF : 0x40C0FF)))) : 0xFFFFFF);
         draw_text(health, (HICON_X + HICON_SIZE + HICON_SPACE)/2, HICON_TEXTY/2, healthcolor.r, healthcolor.g, healthcolor.b);
@@ -889,10 +923,7 @@ namespace game
         {
             if(d->armour) draw_textf("%d", (HICON_X + HICON_STEP + HICON_SIZE + HICON_SPACE)/2, HICON_TEXTY/2, d->armour);
             draw_textf("%d", (HICON_X + 2*HICON_STEP + HICON_SIZE + HICON_SPACE)/2, HICON_TEXTY/2, d->ammo[d->gunselect]);
-            //~draw_textf("%d", (HICON_X + 2*HICON_STEP + HICON_SIZE + HICON_SPACE)/2+800, HICON_TEXTY/2, (int) (100.0f+speedmodifier));
-            draw_textf("%d", (HICON_X + 2*HICON_STEP + HICON_SIZE + HICON_SPACE)/2+400, HICON_TEXTY/2, speedforreal);
         }
-
         pophudmatrix();
 
         if(d->state != CS_DEAD && d->maxhealth > 100)
@@ -1074,15 +1105,47 @@ namespace game
             if(ammobar) drawammobar(w, h, d);
         }
 
+
         if(!m_edit)
         {
-            if(gameclock)   drawgameclock(w, h);
-            if(hudscore)    drawhudscore(w, h);
+            if(gameclock) drawgameclock(w, h);
+            if(hudscore) drawhudscore(w, h);
+            //~if(speedometer) drawspeedometer(d, w, h);
+        }
+
+        /// Speedometer.
+
+        int speedforreal = (int) (sqrtf(d->vel.squaredlen()) + 1.0f);
+        speedforreal = (speedforreal == 1) ? 0 : speedforreal;
+        vec colour = vec(255, 255, 255);
+        float realw = 0;
+        float realh = 0;
+        if (speedometercolor) {
+            if (speedforreal==0)                            colour = vec(60, 60, 60);
+            else if (speedforreal>0   && speedforreal<=60)  colour = vec(240, 30, 30);
+            else if (speedforreal>60  && speedforreal<=120) colour = vec(180, 90, 60);
+            else if (speedforreal>120 && speedforreal<=180) colour = vec(180, 180, 30);
+            else if (speedforreal>180 && speedforreal<=240) colour = vec(90, 180, 60);
+            else                                            colour = vec(30, 240, 30);
         }
 
+        defformatstring(speedstring, "%d", speedforreal);
+        text_boundsf(speedstring, realw, realh);
+        vec2 offset = vec2(speedometerx, speedometery).mul(vec2(w, h).div(speedometerscale));
+        offset.x -= realw/2.0f;
+        offset.y -= realh/2.0f;
+
+        pushhudmatrix();
+        hudmatrix.scale(speedometerscale, speedometerscale, 1);
+        flushhudmatrix();
+
+        draw_text(speedstring, int(offset.x), int(offset.y), colour.x, colour.y, colour.z, (int)(speedometeralpha*255.0f));
+
+        pophudmatrix();
+
         /// Frag message.
 
-        if(hudfragmillis+fragmessageduration > lastmillis)
+        if((hudfragmillis+fragmessageduration > lastmillis) && (lastmillis>fragmessageduration))
         {
             vec2 center = vec2(0.5*w, 0.2*h);
             float width = 0, height = 0;
index 9427864cdbcfcccdd2624b009c99e22b13f4cf0a..ad102f19fd4c26fb2084e1ecf166ae90cd36f730 100644 (file)
@@ -430,6 +430,8 @@ struct fpsstate
     }
 };
 
+extern int screenw, screenh;
+
 struct fpsent : dynent, fpsstate
 {
     int weight;                         // affects the effectiveness of hitpush