home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / Chip_2002-01_cd1.bin / oddech / eracer / cEnemies.cls < prev    next >
Text File  |  2001-02-16  |  4KB  |  152 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 = "cEnemies"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. Public Active                As Boolean
  17. Public D3Frame               As Direct3DRMFrame3
  18. Private I_oEnemy()           As cEnemy
  19. Public Level                 As Single
  20.  
  21. Public ActiveCount           As Long
  22.  
  23. Public D3Mesh                As Direct3DRMMeshBuilder3
  24.  
  25. Public Sub ToggleSound()
  26.     Dim L_nIndex As Integer
  27.     For L_nIndex = 0 To 3
  28.         If I_oEnemy(L_nIndex).D3Frame.GetTraversalOptions <> 0 Then
  29.             If Application.SoundEnabled Then
  30.                 I_oEnemy(L_nIndex).DSB.Play DSBPLAY_LOOPING
  31.             Else
  32.                 I_oEnemy(L_nIndex).DSB.Stop
  33.             End If
  34.         End If
  35.     Next
  36. End Sub
  37.  
  38. Public Sub Initialize()
  39.  
  40.     Dim L_nIndex    As Long
  41.     
  42.     Set D3Frame = Application.D3Instance.CreateFrame(Application.D3Frame)
  43.     
  44.     ReDim I_oEnemy(3) As cEnemy
  45.     
  46.     For L_nIndex = 0 To 3
  47.     
  48.         Set I_oEnemy(L_nIndex) = New cEnemy
  49.         Set I_oEnemy(L_nIndex).Parent = Me
  50.         I_oEnemy(L_nIndex).Initialize
  51.     
  52.     Next
  53.     
  54.     Set D3Mesh = Application.D3Instance.CreateMeshBuilder
  55.     D3Mesh.LoadFromFile App.Path + "\mdl\a01.x", "", D3DRMLOAD_FROMFILE Or D3DRMLOAD_FIRST, Nothing, Nothing
  56.     
  57.     ActiveCount = 0
  58.     Level = 0
  59.     
  60. End Sub
  61.  
  62. Public Function Add(ByRef P_dD3Pos As D3DVECTOR) As cEnemy
  63.  
  64.     Dim L_nIndex As Long
  65.                         
  66.     For L_nIndex = 0 To 3
  67.         If I_oEnemy(L_nIndex).D3Frame.GetTraversalOptions = 0 Then Exit For
  68.     Next
  69.     
  70.     If L_nIndex < 4 Then
  71.         I_oEnemy(L_nIndex).Activate P_dD3Pos
  72.         Set Add = I_oEnemy(L_nIndex)
  73.     Else
  74.         Set Add = Nothing
  75.     End If
  76.     
  77. End Function
  78.  
  79. Public Sub Update()
  80.  
  81.     Dim L_nIndex    As Long
  82.     Dim L_dD3Pos    As D3DVECTOR
  83.     Dim L_nAngle    As Single
  84.     
  85.     For L_nIndex = 0 To 3
  86.         If I_oEnemy(L_nIndex).D3Frame.GetTraversalOptions <> 0 Then I_oEnemy(L_nIndex).Update
  87.     Next
  88.     
  89.     If Active Then
  90.         If ActiveCount = 0 Then
  91.             
  92.             Level = Level + 1
  93.             
  94.             For L_nIndex = 0 To IIf(Level \ 4 > 3, 3, Level \ 3)
  95.             
  96.                 L_nAngle = Rnd * PIVALUE * 2
  97.                 
  98.                 With L_dD3Pos
  99.                     .X = Application.Environment.IslandSize \ 2 + Sin(L_nAngle) * (Application.Environment.IslandSize / 1.5)
  100.                     .Y = -1
  101.                     .Z = Application.Environment.IslandSize \ 2 + Cos(L_nAngle) * (Application.Environment.IslandSize / 1.5)
  102.                 End With
  103.                 
  104.                 Add L_dD3Pos
  105.             
  106.             Next
  107.             
  108.         End If
  109.     End If
  110.     
  111. End Sub
  112.  
  113. Public Sub Reset()
  114.  
  115.     Dim L_nIndex As Long
  116.     For L_nIndex = 0 To 3
  117.         I_oEnemy(L_nIndex).Deactivate
  118.     Next
  119.     Level = 0
  120.     ActiveCount = 0
  121.     
  122. End Sub
  123.  
  124. Public Sub Render()
  125.  
  126.     Dim L_nIndex    As Long
  127.     Dim L_dD3Pos    As D3DVECTOR
  128.     
  129.     Application.DDSurface.SetForeColor RGB(255, 32, 0)
  130.     
  131.     For L_nIndex = 0 To 3
  132.         If I_oEnemy(L_nIndex).D3Frame.GetTraversalOptions <> 0 Then
  133.             I_oEnemy(L_nIndex).D3Frame.GetPosition Nothing, L_dD3Pos
  134.             Application.DDSurface.DrawCircle 45 - Application.Environment.IslandSize \ 2 + Int(L_dD3Pos.X), 45 - Application.Environment.IslandSize \ 2 + Int(L_dD3Pos.Z), 1 + (Application.FrameCount Mod 24) \ 6
  135.         End If
  136.     Next
  137.  
  138. End Sub
  139.  
  140. Public Function HitTest(ByRef P_dD3Pos As D3DVECTOR) As cEnemy
  141.  
  142.     Dim L_nIndex As Long
  143.     
  144.     For L_nIndex = 0 To 3
  145.         If I_oEnemy(L_nIndex).D3Frame.GetTraversalOptions <> 0 Then
  146.             Set HitTest = I_oEnemy(L_nIndex).HitTest(P_dD3Pos)
  147.             If Not (HitTest Is Nothing) Then Exit Function
  148.         End If
  149.     Next
  150.     
  151. End Function
  152.