Advertisement
Chronos_Ouroboros

ZScript radar

Apr 28th, 2019
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1.     const RADAR_SCALE = 10.0; // Scale of the radar
  2.     const RADAR_MAXDIST = 750.0; // Maximum distance it can find actors at
  3.     const RADAR_RADIUS = 50.0; // The radius of the radar's background
  4.  
  5.     protected void DrawRadar (PlayerPawn pPawn, Vector2 radarPos, double TicFrac) {
  6.         DrawImage ("graphics/HUD/Radar/S7RDR0.png", radarPos, DI_SCREEN_RIGHT_TOP | DI_ITEM_RIGHT_TOP);
  7.  
  8.         double angleCos = Cos (-pPawn.angle), angleSin = Sin (-pPawn.angle);
  9.         Vector3 pPawnXYPos = (pPawn.prev + (TicFrac * (pPawn.pos - pPawn.prev)));
  10.         Vector2 radarOffs = (radarPos.x - RADAR_RADIUS, radarPos.y + RADAR_RADIUS);
  11.  
  12.         HUDFont mRadarMarkers = HUDFont.Create (fnt, fnt.GetCharWidth ("A"), true, 1, 1);
  13.         double markerYOffs = mRadarMarkers.mFont.GetHeight () / 2.0;
  14.  
  15.         bool showKeys = CheckInventory ('S7_UpgradeRadarKeys', 1);
  16.  
  17.         let actorFinder = BlockThingsIterator.Create (pPawn, RADAR_MAXDIST);
  18.         Actor curActor;
  19.         while (actorFinder.Next ()) {
  20.             curActor = actorFinder.thing;
  21.  
  22.             int colour;
  23.             if (curActor.bIsMonster) {
  24.                 if (curActor.health > 0)
  25.                     colour = (curActor.isFriend (pPawn)) ? Font.CR_GREEN : Font.CR_RED;
  26.                 else
  27.                     colour = Font.CR_DARKGRAY;
  28.             } else if (showKeys && curActor.bSpecial && curActor is 'Key')
  29.                 colour = Font.CR_GOLD;
  30.             else
  31.                 continue;
  32.  
  33.             // Coords
  34.             Vector3 actorPos = (curActor.prev + (TicFrac * (curActor.pos - curActor.prev)));
  35.             Vector2 worldPos = pPawnXYPos.xy - actorPos.xy, screenPos;
  36.             worldPos /= RADAR_SCALE;
  37.             screenPos.x = (worldPos.x * angleSin + worldPos.y * angleCos);
  38.             screenPos.y = (worldPos.x * angleCos - worldPos.y * angleSin);
  39.  
  40.             if (screenPos.Length () >= RADAR_RADIUS)
  41.                 continue;
  42.  
  43.             // Draw
  44.             DrawString (mRadarMarkers, "B", radarOffs + screenPos - (0, markerYOffs), DI_SCREEN_RIGHT_TOP | DI_TEXT_ALIGN_CENTER | DI_NOSHADOW, colour);
  45.         }
  46.         DrawString (mRadarMarkers, "A", radarOffs - (0, markerYOffs), DI_SCREEN_RIGHT_TOP | DI_TEXT_ALIGN_CENTER | DI_NOSHADOW, Font.CR_BLUE);
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement