Portal HUD

From Oldunreal-Wiki
Revision as of 21:53, 31 August 2013 by Hellkeeper (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
class PortalsHUD extends UnrealHUD;
// This is a subclass of UnrealHUD which adds portals to your view,
// you could also subclass UT's ChallengeHUD to add the portals in UT.
function PostRender(canvas Canvas)
// A function called DrawPortal will be used four times to create
// four extra views.  DrawPortal is a function of the Canvas. Here
// is the function definition:
// Canvas.DrawPortal(int X, int Y, int Width, int Height, actor CamActor,
//                   vector CamLocation, rotator CamRotation,
//                   optional int FOV, optional bool ClearZ);
// Note: (this is for Unreal 224- the problems may be fixed in later verisons)
// - Sprites are reflected from the right side of the screen to the left, and
// from the bottom of the screen to the top, so it is best to use DrawPortal
// at the top-left corner, or taking up the whole top or whole left of the
// screen.
// - The player's mesh won't display unless the player's bBehindView is True
// (you can type "behindview 1" and "behindview 0" in the console to turn
// the behindview on and off)
// - The sound is only calculated for the player's main camera and not for the
// extra views.
// - The CamActor parameter currently doesn't do anything, but you need to put
// in a valid actor there so that the script compiles.
// - ClearZ specifies whether the Z-buffer should be cleared or not- this doesn't
// seem to make any difference.
// - The portals do not resize and reposition themselves when you adjust
// the screen-size using + and -.
// - Parts of the portals which are not part of the world are not visible
// (instead of being black) to see this in action, move into walls
// while watching the "facing player cam" portal.
  local Projectile projectile1, proj;
  local Pawn pawn1, p;
  local rotator CirclingRotation;
  projectile1 = None;
  // Pick the last found projectile (the newest one)
  foreach AllActors(class'projectile', proj)
    projectile1 = proj;
  pawn1 = None;
  foreach AllActors(class'Pawn', p)
    // If the pawn is not the player and is not a HorseFly
    // (portals using individual FlockPawns such as HorseFlies crash
    // Unreal for some reason).
    if (p != owner && !p.IsA('FlockPawn'))
      // pick the last found pawn (the newest one)
      pawn1 = p;
  // Setup the font
  Canvas.Font = Canvas.MedFont;
  Canvas.DrawColor.r = 255;
  Canvas.DrawColor.g = 255;
  Canvas.DrawColor.b = 255;
  // Projectile cam
  if (projectile1 != None)
    // Portal's starting X
    // (the number of pixels from the left side of the screen)
    // Portal's starting Y
    // (the number of pixels from the top of the screen)
    // height of the portal (30% of the total screen width)
    // width of the portal (30% of the total screen height)
    // the camera actor
    // it doesn't seem to make any difference what you put here,
    // as long as it is a valid actor
    // the location of the camera (40 units behind the projectile)
    projectile1.Location -40 * vector(projectile1.Rotation),
    // the rotation of the camera
    // the field of view angle of the camera (optional)
    // Display the title for the portal
    Canvas.SetPos(Canvas.SizeX*0.02, Canvas.SizeY*0.05);
    Canvas.DrawText("Projectile Cam");
    // Display the name of the projectile
    Canvas.SetPos(Canvas.SizeX*0.02, Canvas.SizeY*0.25);
  // pawn cam
  if (pawn1 != None)
    // Display the title for the portal
    Canvas.SetPos(Canvas.SizeX*0.72, Canvas.SizeY*0.05);
    Canvas.DrawText("Pawn Cam");
    // Display the name of the projectile
    Canvas.SetPos(Canvas.SizeX*0.72, Canvas.SizeY*0.25);
  // facing player cam
  // these two portals turn on if behindview is on
  if (PlayerPawn(owner).bBehindView)
     // Start at the player's location and move 100 units
     // in the direction in which they are facing.
     owner.Location + 100*vector(owner.Rotation),
    // Make the camera have the opposite rotation to the player
    // by converting the rotation to a vector, inverting the vector,
    // and converting the vector to a rotation.
    // Display the title for the portal
    Canvas.SetPos(Canvas.SizeX*0.02, Canvas.SizeY*0.75);
    Canvas.DrawText("Facing Player Cam");
    // Circling player camera
    // Begin with the player's rotation,
    CirclingRotation = owner.Rotation;
    // look down,
    CirclingRotation.Pitch -= 8000;
    // and rotate every 10 seconds.
    CirclingRotation.Yaw = (Level.TimeSeconds*65536) / 10;
    // Start at the player's location and go backwards 60 units
    // in the direction of the circling rotation.
    owner.Location - 60*vector(CirclingRotation),
    // Give the camera the circling rotation
    // display the title for the portal
    Canvas.SetPos(Canvas.SizeX*0.72, Canvas.SizeY*0.75);
    Canvas.DrawText("Circling Player Cam");
  // Draw the menu and UnrealHUD on top by calling the PostRender
  // function in our parent class.
class PortalsGameInfo extends UnrealGameInfo;
// In order to have players use the new HUD with portals just make
// a new gametype, and set the HUDType variable to the new HUD class.