I love the smell of UnrealEd crashing in the morning. – tarquin

Legacy:GTA Radar

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

This is a GTA-like radar that I made for a small mod. The GameInfo class holds a list of all of the Objectives in the map. Objectives are Actor classes that trigger missions.

class MyCustomHUD extends HudBase;
 
var Shader MyShader;
var TexScaler MyScaler;
var TexRotator MyRotator, PlayerIconRotator;
var texture MapRadarTexture, HUDMapOpacity, HUDMapBorder, PlayerIcon, WaypointIcon;
var material TargetPawnIcon;
var float RadarScale, MapScale;
 
var MyCustomGame TheGame;
 
simulated event PostBeginPlay()
{
    local MapScaleActor MSA;
 
    Super.PostBeginPlay();
 
    // Set up all of the textures.
    TheGame = MyCustomGame(Level.Game);
    MyShader = New(None) class'Shader';
    MyScaler = New(None) class'TexScaler';
    MyRotator = New(None) class'TexRotator';
    PlayerIconRotator = New(None) class'TexRotator';
    PlayerIconRotator.Material = PlayerIcon;
 
    // Half of the PlayerIcon's texture size.
    PlayerIconRotator.UOffset = 32;
    PlayerIconRotator.VOffset = 32;
 
    // Set up the Radar image, set the rotation point to the middle.
    if(Level.RadarMapImage != none)
    {
        RadarScale = texture(Level.RadarMapImage).UClamp/256;
        MyScaler.Material = Level.RadarMapImage;
        MyScaler.UScale = 2;
        MyScaler.VScale = 2;
        MyScaler.UOffset = 64*RadarScale;
        MyScaler.VOffset = 64*RadarScale;
        MyRotator.Material = MyScaler;
        MyRotator.UOffset = 128*RadarScale;
        MyRotator.VOffset = 128*RadarScale;
        MyShader.Diffuse = MyRotator;
        MyShader.Opacity = HUDMapOpacity;
    }
 
    // MapScaleActor tells the game the ratio between the RadarMap and the actual level.
    foreach AllActors(class'MapScaleActor',MSA)
        MapScale = MSA.MapScale;
}
 
simulated function DrawHudPassA(Canvas C)
{
    local rotator Dir;
    local float Angle;
    local vector PlayerLocZeroed, ObjectiveLocZeroed;
    local int i;
 
    // Get the player's rotation and position on the map.
    if(PawnOwner != none)
    {
        MyScaler.UOffset = (PawnOwner.Location.X/(MapScale/(256*RadarScale))) + (64*RadarScale);
        MyScaler.VOffset = (PawnOwner.Location.Y/(MapScale/(256*RadarScale))) + (64*RadarScale);
        MyRotator.Rotation.Yaw = PlayerOwner.CalcViewRotation.Yaw + 16384;
        PlayerIconRotator.Rotation.Yaw = PlayerOwner.CalcViewRotation.Yaw - PawnOwner.Rotation.Yaw;
    }
 
    // Draw the Radar Image
    C.SetDrawColor(150,150,150);
    C.SetPos(32*C.ClipX/1280,C.ClipY - (288*C.ClipY/1024));
    C.DrawTileScaled(MyShader,(C.ClipX/1280)/RadarScale,(C.ClipY/1024)/RadarScale);
    C.SetDrawColor(200,200,200);
    C.SetPos(32*C.ClipX/1280,C.ClipY - (288*C.ClipY/1024));
    C.DrawTileScaled(HUDMapBorder,(C.ClipX/1280)/RadarScale,(C.ClipY/1024)/RadarScale);
 
    // Draw the Player Icon
    C.SetPos(144*C.ClipX/1280,C.ClipY - (176*C.ClipY/1024));
    C.SetDrawColor(255,75,255);
    C.DrawTileScaled(PlayerIconRotator,0.5*C.ClipX/1280,0.5*C.ClipY/1024);
 
    // Objective icons
    if(TheGame != None)
    {
        for(i=0;i<TheGame(Level.Game).Objectives.Length;i++)
        {
            if(TheGame(Level.Game).Objectives[i].bEnabled && !TheGame(Level.Game).Objectives[i].bHidden)
            {
            	Dir = rotator(TheGame(Level.Game).Objectives[i].Location - PawnOwner.Location);
            	Angle = ((Dir.Yaw - PlayerOwner.CalcViewRotation.Yaw) & 65535) * 6.2832/65536;
 
            	PlayerLocZeroed = PawnOwner.Location;
            	PlayerLocZeroed.Z = 0;
            	ObjectiveLocZeroed = TheGame(Level.Game).Objectives[i].Location;
            	ObjectiveLocZeroed.Z = 0;
 
                C.SetPos((144*C.ClipX/1280)+(128 * FMin(VSize(PlayerLocZeroed-ObjectiveLocZeroed)/(MapScale/4),1) * sin(Angle) * C.ClipX/1280),
         			    (C.ClipY-(176*C.ClipY/1024)) - (128*FMin(VSize(PlayerLocZeroed-ObjectiveLocZeroed)/(MapScale/4),1) * cos(Angle) * C .ClipY/1024));
                C.SetDrawColor(TheGame(Level.Game).Objectives[i].ObjectiveIconColor.R,
                               TheGame(Level.Game).Objectives[i].ObjectiveIconColor.G,
                               TheGame(Level.Game).Objectives[i].ObjectiveIconColor.B);
            	C.DrawTileScaled(TheGame(Level.Game).Objectives[i].ObjectiveIcon,0.5*C.ClipX/1280,0.5*C.ClipY/1024);
            }
        }
    }
 
    DrawCrosshair(C);
}
 
defaultproperties
{
    HUDMapOpacity=Texture'MyTextures.HUDMapOpacity'
    HUDMapBorder=Texture'MyTextures.HUDMapBorder'
    PlayerIcon=Texture'ONSInterface-TX.CurrentPlayerIcon'
    WaypointIcon=texture'MyTextures.ObjectiveWaypointTex'
    TargetPawnIcon=material'MyTextures.ObjectivePawnFinal'
}

The HUDMapOpacity is a texture with a white circle in the alpha, so that the map is displayed as a circle and not a square.