home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / Chip_2002-01_cd1.bin / oddech / eracer / cInterface.cls < prev    next >
Text File  |  2001-02-16  |  20KB  |  474 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cInterface"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. ' OPTION SETTINGS ...
  15.  
  16.     ' Enforce variable declarations
  17.     Option Explicit
  18.  
  19. ' PRIVATE VARIABLES ...
  20.  
  21.     Private I_oDDSBar           As DirectDrawSurface4        ' Surface holding bar display
  22.     Private I_oDDSBar2          As DirectDrawSurface4        ' Surface holding 2nd bar display
  23.     Private I_oDDSDamage        As DirectDrawSurface4        ' Surface holding bar display element
  24.     Private I_oDDSFuel          As DirectDrawSurface4        ' Surface holding bar display element
  25.     Private I_oDDSSpeed         As DirectDrawSurface4        ' Surface holding bar display element
  26.     Private I_oDDSAgrav         As DirectDrawSurface4        ' Surface holding bar display element
  27.     Private I_oDDSCursor        As DirectDrawSurface4        ' Surface holding cursor
  28.     Private I_oDDSCombat        As DirectDrawSurface4        ' Surface holding combat sign
  29.     Private I_oDDSText          As DirectDrawSurface4        ' Surface holding scrolling text
  30.     Private I_oDDSSnd           As DirectDrawSurface4        ' Surface holding sound sign
  31.     
  32.     Private I_nTextPos          As Single                    ' Position of scrolling text
  33.     Private I_nViewportSize     As Long                      ' Size of 3D viewport
  34.     Public MessageInProgress    As Boolean
  35.     
  36.     Public ViewportSizeChanged  As Boolean
  37.     
  38.     
  39. ' CODE ...
  40.  
  41.     '
  42.     ' DISPLAYMESSAGE: Displays a message in the interface
  43.     '
  44.     Public Sub DisplayMessage(ByVal P_sMessage As String)
  45.     
  46.         Dim L_dArea As RECT
  47.         Static S_sMessage As String
  48.         
  49.         If P_sMessage = S_sMessage Then Exit Sub
  50.         S_sMessage = P_sMessage
  51.         
  52.         With L_dArea
  53.             .Left = 0
  54.             .Top = 0
  55.             .Right = 640
  56.             .Bottom = 15
  57.         End With
  58.         
  59.         I_oDDSText.BltColorFill L_dArea, 0
  60.         I_oDDSText.SetForeColor RGB(0, 255, 0)
  61.         I_oDDSText.SetFont fER.Font
  62.         
  63.         I_oDDSText.DrawText 122, 1, P_sMessage, False
  64.         
  65.         I_nTextPos = 640
  66.             
  67.         MessageInProgress = True
  68.         
  69.     End Sub
  70.     
  71.     
  72.     '
  73.     ' INITIALIZE: Initialize interface
  74.     '
  75.     Public Sub Initialize()
  76.             
  77.         ' Declare local variables ...
  78.         
  79.             Dim L_dDDSD         As DDSURFACEDESC2           ' Surface descriptor for creating primary and bbuffer
  80.             Dim L_dDDCK         As DDCOLORKEY               ' Color key for making surfaces transparent
  81.  
  82.         ' Code ...
  83.         
  84.             ' Prepare surface description
  85.             With L_dDDSD
  86.                 .lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
  87.                 .ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
  88.                 .lWidth = 0
  89.                 .lHeight = 0
  90.             End With
  91.             
  92.             ' Prepare color key
  93.             With L_dDDCK
  94.                 .low = 0
  95.                 .high = 0
  96.             End With
  97.             
  98.             ' Load and prepare bar display ...
  99.                 
  100.                 L_dDDSD.lWidth = 640
  101.                 L_dDDSD.lHeight = 90
  102.                 Set I_oDDSBar = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\bar.bmp", L_dDDSD)
  103.                 I_oDDSBar.SetColorKey DDCKEY_SRCBLT, L_dDDCK
  104.                 
  105.                 L_dDDSD.lWidth = 160
  106.                 L_dDDSD.lHeight = 90
  107.                 Set I_oDDSBar2 = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\bar2.bmp", L_dDDSD)
  108.                 I_oDDSBar2.SetColorKey DDCKEY_SRCBLT, L_dDDCK
  109.                 
  110.                 L_dDDSD.lWidth = 94
  111.                 L_dDDSD.lHeight = 20
  112.                 Set I_oDDSFuel = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\fuel.bmp", L_dDDSD)
  113.                 I_oDDSFuel.SetColorKey DDCKEY_SRCBLT, L_dDDCK
  114.                 
  115.                 L_dDDSD.lWidth = 106
  116.                 L_dDDSD.lHeight = 13
  117.                 Set I_oDDSDamage = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\damage.bmp", L_dDDSD)
  118.                 I_oDDSDamage.SetColorKey DDCKEY_SRCBLT, L_dDDCK
  119.                 
  120.                 L_dDDSD.lWidth = 52
  121.                 L_dDDSD.lHeight = 25
  122.                 Set I_oDDSSpeed = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\speed.bmp", L_dDDSD)
  123.                 I_oDDSSpeed.SetColorKey DDCKEY_SRCBLT, L_dDDCK
  124.                 
  125.                 L_dDDSD.lWidth = 18
  126.                 L_dDDSD.lHeight = 25
  127.                 Set I_oDDSAgrav = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\agrav.bmp", L_dDDSD)
  128.                 I_oDDSAgrav.SetColorKey DDCKEY_SRCBLT, L_dDDCK
  129.                 
  130.                 L_dDDSD.lWidth = 16
  131.                 L_dDDSD.lHeight = 16
  132.                 Set I_oDDSCursor = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\cursor.bmp", L_dDDSD)
  133.                 I_oDDSCursor.SetColorKey DDCKEY_SRCBLT, L_dDDCK
  134.                 
  135.                 L_dDDSD.lWidth = 34
  136.                 L_dDDSD.lHeight = 33
  137.                 Set I_oDDSCombat = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\combat.bmp", L_dDDSD)
  138.                 I_oDDSCombat.SetColorKey DDCKEY_SRCBLT, L_dDDCK
  139.                         
  140.                 L_dDDSD.lWidth = 17
  141.                 L_dDDSD.lHeight = 17
  142.                 Set I_oDDSSnd = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\snd.bmp", L_dDDSD)
  143.                 I_oDDSSnd.SetColorKey DDCKEY_SRCBLT, L_dDDCK
  144.                         
  145.             ' Prepare scrolling text surface
  146.                 L_dDDSD.lWidth = 640
  147.                 L_dDDSD.lHeight = 15
  148.                 Set I_oDDSText = Application.DDInstance.CreateSurface(L_dDDSD)
  149.                 
  150.         ' Initialize general data ...
  151.             
  152.             ' Set initial viewport size
  153.             ViewportSize = 11
  154.                 
  155.     End Sub
  156.  
  157.     '
  158.     ' RENDER: Render 2D interface to backbuffer
  159.     '
  160.     Public Sub Render(Optional ByVal P_bRenderLoading As Boolean)
  161.  
  162.         ' Declare local variables ...
  163.         
  164.             Dim L_dArea         As RECT                 ' Area from/to which to render
  165.             Dim L_dDDSD         As DDSURFACEDESC2       ' Descriptor for loading static surfaces
  166.             
  167.             Static S_oDDSLogo   As DirectDrawSurface4   ' Surface holding logo
  168.             Static S_oDDSLoad   As DirectDrawSurface4   ' Surface holding loading sign
  169.             Static S_oDDSEracer As DirectDrawSurface4   ' Surface holding game logo
  170.             
  171.         ' Code ...
  172.         
  173.             ' Load static surfaces ...
  174.                                         
  175.                 ' Logo ...
  176.                 
  177.                     If S_oDDSLogo Is Nothing Then
  178.                         
  179.                         ' Prepare surface descriptor
  180.                         With L_dDDSD
  181.                             .lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
  182.                             .ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
  183.                             .lWidth = 359
  184.                             .lHeight = 59
  185.                         End With
  186.                         
  187.                         ' Load
  188.                         Set S_oDDSLogo = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\nls.bmp", L_dDDSD)
  189.                 
  190.                     End If
  191.                     
  192.                 ' Eracer Logo ...
  193.                 
  194.                     If S_oDDSEracer Is Nothing Then
  195.                         
  196.                         ' Prepare surface descriptor
  197.                         With L_dDDSD
  198.                             .lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
  199.                             .ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
  200.                             .lWidth = 240
  201.                             .lHeight = 60
  202.                         End With
  203.                         
  204.                         ' Load
  205.                         Set S_oDDSEracer = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\logo.bmp", L_dDDSD)
  206.                 
  207.                     End If
  208.                     
  209.                 ' Loading sign ...
  210.                 
  211.                     If S_oDDSLoad Is Nothing Then
  212.                         
  213.                         ' Prepare surface descriptor
  214.                         With L_dDDSD
  215.                             .lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
  216.                             .ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
  217.                             .lWidth = 178
  218.                             .lHeight = 26
  219.                         End With
  220.                         
  221.                         ' Load
  222.                         Set S_oDDSLoad = Application.DDInstance.CreateSurfaceFromFile(App.Path + "\gfx\loading.bmp", L_dDDSD)
  223.                 
  224.                     End If
  225.                     
  226.             ' Loading display ...
  227.             
  228.                 If P_bRenderLoading Then
  229.                                     
  230.                     ' Clear background ...
  231.                     
  232.                         With L_dArea
  233.                             .Left = 0
  234.                             .Top = 0
  235.                             .Right = 640
  236.                             .Bottom = 480
  237.                         End With
  238.                         Application.DDSurface.BltColorFill L_dArea, 0
  239.                     
  240.                     ' Logo ...
  241.                     
  242.                         With L_dArea
  243.                             .Left = 0
  244.                             .Top = 0
  245.                             .Right = 359
  246.                             .Bottom = 59
  247.                         End With
  248.                         Application.DDSurface.BltFast 5, 415, S_oDDSLogo, L_dArea, DDBLTFAST_NOCOLORKEY Or DDBLTFAST_WAIT
  249.                     
  250.                     ' Sign ...
  251.                     
  252.                         With L_dArea
  253.                             .Left = 0
  254.                             .Top = 0
  255.                             .Right = 240
  256.                             .Bottom = 60
  257.                         End With
  258.                         Application.DDSurface.BltFast 360, 40, S_oDDSEracer, L_dArea, DDBLTFAST_NOCOLORKEY Or DDBLTFAST_WAIT
  259.                        
  260.                     ' Loading sign ...
  261.                     
  262.                         With L_dArea
  263.                             .Left = 0
  264.                             .Top = 0
  265.                             .Right = 178
  266.                             .Bottom = 26
  267.                         End With
  268.                         Application.DDSurface.BltFast 231, 232, S_oDDSLoad, L_dArea, DDBLTFAST_NOCOLORKEY Or DDBLTFAST_WAIT
  269.                 
  270.                     ' Instantly update primary
  271.                     
  272.                         With L_dArea
  273.                             .Left = 0
  274.                             .Top = 0
  275.                             .Right = 640
  276.                             .Bottom = 480
  277.                         End With
  278.                         Application.DDPrimary.BltFast 0, 0, Application.DDSurface, L_dArea, DDBLTFAST_NOCOLORKEY Or DDBLTFAST_WAIT
  279.                         
  280.                     ' Finished
  281.                     Exit Sub
  282.                 
  283.                 End If
  284.                 
  285.             ' Menu display ...
  286.             
  287.                 ' Default configuration ...
  288.             
  289.                     With L_dArea
  290.                         .Left = 0
  291.                         .Top = 0
  292.                         .Right = 160
  293.                         .Bottom = 90
  294.                     End With
  295.                     Application.DDSurface.BltFast 480, 390, I_oDDSBar2, L_dArea, DDBLTFAST_SRCCOLORKEY Or DDBLTFAST_WAIT
  296.                 
  297.                 ' Blinking combat sign  ...
  298.                 
  299.                     If Application.Enemies.Active Then
  300.                         If Application.FrameCount Mod 30 < 15 Then
  301.                         
  302.                             With L_dArea
  303.                                 .Left = 0
  304.                                 .Top = 0
  305.                                 .Right = 34
  306.                                 .Bottom = 33
  307.                             End With
  308.                             Application.DDSurface.BltFast 480 + 74, 390 + 46, I_oDDSCombat, L_dArea, DDBLTFAST_SRCCOLORKEY Or DDBLTFAST_WAIT
  309.                             
  310.                         End If
  311.                     End If
  312.             
  313.                 ' Sound enabled sign ...
  314.                 
  315.                     If Application.SoundEnabled Then
  316.                         With L_dArea
  317.                             .Left = 0
  318.                             .Top = 0
  319.                             .Right = 17
  320.                             .Bottom = 17
  321.                         End With
  322.                         Application.DDSurface.BltFast 480 + 118, 390 + 33, I_oDDSSnd, L_dArea, DDBLTFAST_SRCCOLORKEY Or DDBLTFAST_WAIT
  323.                     End If
  324.                     
  325.             ' Bar display ...
  326.             
  327.                 ' Background ...
  328.                 
  329.                     ' Set area
  330.                     With L_dArea
  331.                         .Left = 0
  332.                         .Top = 0
  333.                         .Right = 640
  334.                         .Bottom = 90
  335.                     End With
  336.                     
  337.                     ' Render
  338.                     Application.DDSurface.BltFast 0, 0, I_oDDSBar, L_dArea, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY
  339.                 
  340.                 ' FPS display ...
  341.                                     
  342.                     Application.DDSurface.SetForeColor RGB(32, 32, 32)
  343.                     Application.DDSurface.DrawLine 573, 24, 630, 24
  344.                     Application.DDSurface.SetForeColor RGB((55 - Application.FrameRate) * 5, Application.FrameRate * 5, 0)
  345.                     Application.DDSurface.DrawLine 573, 24, 575 + Application.FrameRate, 24
  346.                                     
  347.                 ' Game related...
  348.                 
  349.                     ' Map on bar display ...
  350.                     
  351.                         ' Set area
  352.                         Application.Environment.DDSMap.GetSurfaceDesc L_dDDSD
  353.                         With L_dArea
  354.                             .Left = 0
  355.                             .Top = 0
  356.                             .Right = L_dDDSD.lWidth
  357.                             .Bottom = L_dDDSD.lHeight
  358.                         End With
  359.                         
  360.                         ' Render
  361.                         Application.DDSurface.BltFast 45 - L_dDDSD.lWidth \ 2, 45 - L_dDDSD.lHeight \ 2, Application.Environment.DDSMap, L_dArea, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY
  362.                     
  363.                         ' Set player
  364.                         Application.DDSurface.SetForeColor RGB(0, 128, 255)
  365.                         Application.DDSurface.DrawCircle 45 - L_dDDSD.lWidth \ 2 + Application.Player.X, 45 - L_dDDSD.lHeight \ 2 + Application.Player.Z, 1 + (Application.FrameCount Mod 24) \ 6
  366.                         Application.DDSurface.DrawLine 45 - L_dDDSD.lWidth \ 2 + Application.Player.X, 45 - L_dDDSD.lHeight \ 2 + Application.Player.Z, 45 - L_dDDSD.lWidth \ 2 + Application.Player.X + Cos(Application.Player.Heading) * 4, 45 - L_dDDSD.lHeight \ 2 + Application.Player.Z + Sin(Application.Player.Heading) * 4
  367.                         
  368.                         ' Set enemies
  369.                         Application.Enemies.Render
  370.                     
  371.                     ' Info display ...
  372.                     
  373.                         ' Damage
  374.                         With L_dArea
  375.                             .Left = 0
  376.                             .Top = 0
  377.                             .Right = 106 * (Application.Player.Health / IIf(Application.Player.Model = rmWarthog, 1000, 700))
  378.                             .Bottom = 13
  379.                         End With
  380.                         Application.DDSurface.BltFast 92, 15, I_oDDSDamage, L_dArea, DDBLTFAST_SRCCOLORKEY Or DDBLTFAST_WAIT
  381.                                             
  382.                         ' Fuel
  383.                         With L_dArea
  384.                             .Left = 0
  385.                             .Top = 0
  386.                             .Right = 94 * (Application.Player.Fuel / IIf(Application.Player.Model = rmJaguar, 10500, 16500))
  387.                             .Bottom = 20
  388.                         End With
  389.                         Application.DDSurface.BltFast 92, 25, I_oDDSFuel, L_dArea, DDBLTFAST_SRCCOLORKEY Or DDBLTFAST_WAIT
  390.                         
  391.                         ' Speed
  392.                         With L_dArea
  393.                             .Left = 0
  394.                             .Top = 0
  395.                             .Right = 52 * IIf(Application.Player.Velocity > 0, (Application.Player.Velocity / IIf(Application.Player.Model = rmJaguar, 0.125, 0.1)), 0)
  396.                             .Bottom = 25
  397.                         End With
  398.                         Application.DDSurface.BltFast 117, 50, I_oDDSSpeed, L_dArea, DDBLTFAST_SRCCOLORKEY Or DDBLTFAST_WAIT
  399.                         
  400.                         ' Agrav
  401.                         With L_dArea
  402.                             .Left = 0
  403.                             .Top = 25 - Application.Player.Hoover * 200
  404.                             .Right = 18
  405.                             .Bottom = 25
  406.                         End With
  407.                         Application.DDSurface.BltFast 92, 75 - Application.Player.Hoover * 200, I_oDDSAgrav, L_dArea, DDBLTFAST_SRCCOLORKEY Or DDBLTFAST_WAIT
  408.             
  409.                     ' Text display
  410.                     
  411.                         If I_nTextPos > 122 Then
  412.                             
  413.                             I_nTextPos = I_nTextPos - 1
  414.                             With L_dArea
  415.                                 .Left = (640 - I_nTextPos)
  416.                                 .Top = 0
  417.                                 .Right = .Left + 122
  418.                                 .Bottom = 15
  419.                             End With
  420.                             Application.DDSurface.BltFast 219, 10, I_oDDSText, L_dArea, DDBLTFAST_NOCOLORKEY Or DDBLTFAST_WAIT
  421.                             
  422.                         Else
  423.                             MessageInProgress = False
  424.                         End If
  425.     End Sub
  426.  
  427.     '
  428.     ' VIEWPORTSIZE GET: Return size of viewport
  429.     '
  430.     Public Property Get ViewportSize() As Long
  431.         ViewportSize = I_nViewportSize
  432.     End Property
  433.     
  434.     '
  435.     ' VIEWPORTSIZE LET: Set size of viewport, create accordingly
  436.     '
  437.     Public Property Let ViewportSize(ByVal P_nViewportSize As Long)
  438.     
  439.         ' Declare local variables ...
  440.             
  441.             Dim L_dArea As RECT ' Area for clearing
  442.             
  443.         ' Code ...
  444.             
  445.             ' Clear background ...
  446.             
  447.                 With L_dArea
  448.                     .Left = 0
  449.                     .Top = 0
  450.                     .Right = 640
  451.                     .Bottom = 480
  452.                 End With
  453.                 Application.DDSurface.BltColorFill L_dArea, 0
  454.         
  455.             ' Create and configure new viewport ...
  456.             
  457.                 Set Application.D3Viewport = Application.D3Instance.CreateViewport(Application.D3Device, Application.D3Camera, P_nViewportSize * 9, P_nViewportSize * 6, 640 - P_nViewportSize * 18, 480 - P_nViewportSize * 12)
  458.                 With Application.D3Viewport
  459.                     .SetFront 0.25
  460.                     .SetBack 20
  461.                     .SetField 0.3
  462.                 End With
  463.         
  464.             ' Remember size ...
  465.             
  466.                 I_nViewportSize = P_nViewportSize
  467.                 
  468.             ' Flag change ...
  469.             
  470.                 ViewportSizeChanged = True
  471.                 
  472.         
  473.     End Property
  474.