home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / Chip_2002-01_cd1.bin / oddech / eracer / cEffect.cls < prev    next >
Text File  |  2001-02-16  |  6KB  |  185 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 = "cEffect"
  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 Parent           As cEffects
  17. Public D3Frame          As Direct3DRMFrame3
  18.  
  19. Private I_oDDSTexture   As DirectDrawSurface4
  20. Private I_oDDSSource    As DirectDrawSurface4
  21. Private I_oD3Texture    As Direct3DRMTexture3
  22.  
  23. Private I_nType         As eEffectType
  24. Private I_nScale        As Single
  25. Private I_nAlpha        As Single
  26. Private I_nCount        As Long
  27.  
  28. Private I_oDSB              As DirectSoundBuffer
  29. Private I_oD3B              As DirectSound3DBuffer
  30.  
  31. Public Sub Initialize()
  32.  
  33.     Dim L_dDDSD         As DDSURFACEDESC2
  34.     Dim L_oD3Mesh       As Direct3DRMMeshBuilder3
  35.     Dim L_oD3Material   As Direct3DRMMaterial2
  36.     
  37.     Set D3Frame = Application.D3Instance.CreateFrame(Application.D3Frame)
  38.     D3Frame.SetTraversalOptions 0
  39.     
  40.     With L_dDDSD
  41.         .lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
  42.         .lHeight = 32
  43.         .lWidth = 32
  44.         .ddsCaps.lCaps = DDSCAPS_TEXTURE
  45.     End With
  46.                         
  47.     Set I_oDDSTexture = Application.DDInstance.CreateSurface(L_dDDSD)
  48.     
  49.     Set I_oD3Texture = Application.D3Instance.CreateTextureFromSurface(I_oDDSTexture)
  50.     With I_oD3Texture
  51.         .SetDecalTransparency D_TRUE
  52.         .SetDecalTransparentColor 0
  53.     End With
  54.     
  55.     D3Frame.AddVisual GenerateBaseMesh(1, I_oD3Texture)
  56.     
  57.     If (Not Application.DSInstance Is Nothing) Then
  58.         
  59.         Dim L_ddsbd As DSBUFFERDESC
  60.         With L_ddsbd
  61.             .lBufferBytes = 0
  62.             .lFlags = DSBCAPS_CTRL3D Or DSBCAPS_CTRLFREQUENCY Or DSBCAPS_CTRLPAN Or DSBCAPS_CTRLVOLUME Or DSBCAPS_STATIC
  63.         End With
  64.         
  65.         Set I_oDSB = Application.DSInstance.CreateSoundBufferFromFile(App.Path + "\snd\explosmall.wav", L_ddsbd, GetWaveFileFormat(App.Path + "\snd\explosmall.wav"))
  66.         Set I_oD3B = I_oDSB.GetDirectSound3DBuffer
  67.         With I_oD3B
  68.             .SetConeAngles DS3D_MINCONEANGLE, DS3D_MAXCONEANGLE, DS3D_IMMEDIATE
  69.             .SetConeOutsideVolume 0, DS3D_IMMEDIATE
  70.             .SetMinDistance 1, DS3D_IMMEDIATE
  71.             .SetMaxDistance 15, DS3D_IMMEDIATE
  72.             .SetVelocity 0, 0, 0, DS3D_IMMEDIATE
  73.             .SetMode DS3DMODE_NORMAL, DS3D_IMMEDIATE
  74.         End With
  75.         
  76.     End If
  77. End Sub
  78.  
  79. Public Sub Update()
  80.             
  81.     Dim L_dArea     As RECT
  82.     Dim L_dAreas(0) As RECT
  83.     Dim L_dD3Ori    As D3DVECTOR
  84.     Dim L_dD3Nor    As D3DVECTOR
  85.     Dim L_oD3MO     As D3DRMMATERIALOVERRIDE
  86.     
  87.     If D3Frame.GetTraversalOptions = 0 Then Exit Sub
  88.     
  89.     I_nCount = I_nCount - 1
  90.     
  91.     With L_dArea
  92.         .Left = 32 * (((36 - I_nCount) \ 3) Mod 4)
  93.         .Top = 32 * (((36 - I_nCount) \ 3) \ 4)
  94.         .Right = .Left + 32
  95.         .Bottom = .Top + 32
  96.     End With
  97.     
  98.     I_oDDSTexture.BltFast 0, 0, I_oDDSSource, L_dArea, DDBLTFAST_NOCOLORKEY Or DDBLTFAST_WAIT
  99.     I_oD3Texture.Changed D3DRMTEXTURE_CHANGEDPIXELS, 0, L_dAreas
  100.     
  101.     Application.D3Camera.GetOrientation Nothing, L_dD3Ori, L_dD3Nor
  102.     D3Frame.SetOrientation Nothing, L_dD3Ori.X, L_dD3Ori.Y, L_dD3Ori.Z, L_dD3Nor.X, L_dD3Nor.Y, L_dD3Nor.Z
  103.                                         
  104.     With L_oD3MO
  105.         .lFlags = D3DRMMATERIALOVERRIDE_DIFFUSE_ALPHAONLY Or D3DRMMATERIALOVERRIDE_DIFFUSE_ALPHAMULTIPLY
  106.         .dcDiffuse.a = I_nAlpha * (I_nCount / 36)
  107.     End With
  108.     D3Frame.SetMaterialOverride L_oD3MO
  109.     
  110.     If I_nCount = 0 Then Deactivate
  111.  
  112. End Sub
  113.  
  114. Public Sub Activate(ByVal P_nType As eEffectType, ByRef P_dD3Pos As D3DVECTOR, ByRef P_dD3Vel As D3DVECTOR)
  115.  
  116.     Dim L_oD3Mesh As Direct3DRMMeshBuilder3
  117.     
  118.     Select Case P_nType
  119.         
  120.         Case etShotPlayer
  121.             
  122.             Set I_oDDSSource = Parent.DDSurfaceShotPlayer
  123.             D3Frame.SetVelocity Nothing, 0, 0, 0, D_FALSE
  124.             I_nType = etShotPlayer
  125.             I_nCount = 36
  126.             I_nScale = 0.25
  127.             I_nAlpha = 1
  128.             If (Not Application.DSInstance Is Nothing) And Application.SoundEnabled Then
  129.                 I_oD3B.SetPosition P_dD3Pos.X, P_dD3Pos.Y, P_dD3Pos.Z, DS3D_IMMEDIATE
  130.                 I_oD3B.SetConeOrientation 0, 1, 0, DS3D_IMMEDIATE
  131.                 I_oDSB.Play DSBPLAY_DEFAULT
  132.             End If
  133.             
  134.         Case etShotEnemy
  135.         
  136.             Set I_oDDSSource = Parent.DDSurfaceShotEnemy
  137.             D3Frame.SetVelocity Nothing, 0, 0, 0, D_FALSE
  138.             I_nType = etShotEnemy
  139.             I_nCount = 36
  140.             I_nScale = 0.2
  141.             I_nAlpha = 1
  142.             If (Not Application.DSInstance Is Nothing) And Application.SoundEnabled Then
  143.                 I_oD3B.SetPosition P_dD3Pos.X, P_dD3Pos.Y, P_dD3Pos.Z, DS3D_IMMEDIATE
  144.                 I_oD3B.SetConeOrientation 0, 1, 0, DS3D_IMMEDIATE
  145.                 I_oDSB.Play DSBPLAY_DEFAULT
  146.             End If
  147.             
  148.         Case etExplo
  149.         
  150.             Set I_oDDSSource = Parent.DDSurfaceExplo
  151.             D3Frame.SetVelocity Nothing, 0, 0, 0, D_FALSE
  152.             I_nType = etExplo
  153.             I_nCount = 30
  154.             I_nScale = 0.3
  155.             I_nAlpha = 1
  156.             
  157.     End Select
  158.     
  159.     D3Frame.SetTraversalOptions D3DRMFRAME_RENDERENABLE
  160.     D3Frame.SetPosition Nothing, P_dD3Pos.X, P_dD3Pos.Y, P_dD3Pos.Z
  161.     D3Frame.SetVelocity Nothing, P_dD3Vel.X, P_dD3Vel.Y, P_dD3Vel.Z, D_FALSE
  162.     
  163.     Set L_oD3Mesh = D3Frame.GetVisual(0)
  164.     L_oD3Mesh.ScaleMesh I_nScale, I_nScale, I_nScale
  165.     
  166.     Update
  167.     
  168. End Sub
  169.  
  170. Public Sub Deactivate()
  171.  
  172.     Dim L_oD3Mesh As Direct3DRMMeshBuilder3
  173.     
  174.     If D3Frame.GetTraversalOptions = 0 Then Exit Sub
  175.     
  176.     D3Frame.SetTraversalOptions 0
  177.     D3Frame.SetVelocity Nothing, 0, 0, 0, D_FALSE
  178.     
  179.     Set L_oD3Mesh = D3Frame.GetVisual(0)
  180.     L_oD3Mesh.ScaleMesh 1 / I_nScale, 1 / I_nScale, 1 / I_nScale
  181.  
  182.     
  183. End Sub
  184.  
  185.