📄 cenemy.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "cEnemy"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Const Life As Long = 10
Private Const FSize = 0.5
Private Const CDown As Long = 1000
Private StartAnim As Long
Private CurrAnim As Integer
Private AnimLength(1 To 3) As Long
Private KeyFrame1() As D3DVERTEX
Private KeyFrame2() As D3DVERTEX
Private KeyFrame3() As D3DVERTEX
Private KeyFrame4() As D3DVERTEX
Private KeyFrame5() As D3DVERTEX
Private Interpol() As D3DVERTEX
Private Infin As Integer
Private TempV As D3DVECTOR
Private Mesh As D3DXMesh
Private CTime As Long
Private Interval As Single
Private NumMaterials As Long
Private Materials() As D3DMATERIAL8
Private Textures() As Direct3DTexture8
Private Position As D3DVECTOR
Public tLife As Long
Private EMove As D3DMATRIX
Private ERotate As D3DMATRIX
Private EMatrix As D3DMATRIX
Public CAngle As Single
Private LookDir As D3DVECTOR
Private mIdentity As D3DMATRIX
Private TV As D3DVECTOR
Private WayPoints(1 To 9) As D3DVECTOR
Private TurnPoints(1 To 9) As Single
Private CurrWaypoint As Integer
Private TTN As Single
Private LastUpdate As Long
Private Mouth As D3DVECTOR
Private SVisible As Integer
Private SHList(1) As CHVERTEX
Private ShootCool As Single
Private Death As Boolean
Private FList(11) As FVERTEX
Private SoundShoot As New cSound
Private FlashTexture As Direct3DTexture8
Private FlashTrans As D3DMATRIX
Private Spotted As Boolean
Public Function Init(Path As String)
Dim mtrlBuffer As D3DXBuffer
Dim I As Long
Dim TextureFile As String
Death = False
Set Mesh = D3DX.LoadMeshFromX(Path, D3DXMESH_MANAGED, D3DDevice, Nothing, mtrlBuffer, NumMaterials)
ReDim Materials(NumMaterials) As D3DMATERIAL8
ReDim Textures(NumMaterials) As Direct3DTexture8
For I = 0 To NumMaterials - 1
D3DX.BufferGetMaterial mtrlBuffer, I, Materials(I)
Materials(I).Ambient = Materials(I).diffuse
TextureFile = D3DX.BufferGetTextureName(mtrlBuffer, I)
If TextureFile <> "" Then
Set Textures(I) = D3DX.CreateTextureFromFile(D3DDevice, App.Path + "\ENE-1" + TextureFile)
End If
Next I
Set FlashTexture = D3DX.CreateTextureFromFile(D3DDevice, App.Path + "\flash.bmp")
ReDim KeyFrame1(0 To Mesh.GetNumVertices) As D3DVERTEX
ReDim KeyFrame2(0 To Mesh.GetNumVertices) As D3DVERTEX
ReDim KeyFrame3(0 To Mesh.GetNumVertices) As D3DVERTEX
ReDim KeyFrame4(0 To Mesh.GetNumVertices) As D3DVERTEX
ReDim KeyFrame5(0 To Mesh.GetNumVertices) As D3DVERTEX
ReDim Interpol(0 To Mesh.GetNumVertices) As D3DVERTEX
D3DXMeshVertexBuffer8GetData Mesh, 0, Len(Interpol(0)) * Mesh.GetNumVertices, 0, KeyFrame1(0)
D3DXMeshVertexBuffer8GetData Mesh, 0, Len(Interpol(0)) * Mesh.GetNumVertices, 0, Interpol(0)
Set Mesh = D3DX.LoadMeshFromX(App.Path + "\Ene2.x", D3DXMESH_MANAGED, D3DDevice, Nothing, mtrlBuffer, NumMaterials)
D3DXMeshVertexBuffer8GetData Mesh, 0, Len(Interpol(0)) * Mesh.GetNumVertices, 0, KeyFrame2(0)
Set Mesh = D3DX.LoadMeshFromX(App.Path + "\Ene3.x", D3DXMESH_MANAGED, D3DDevice, Nothing, mtrlBuffer, NumMaterials)
D3DXMeshVertexBuffer8GetData Mesh, 0, Len(Interpol(0)) * Mesh.GetNumVertices, 0, KeyFrame3(0)
Set Mesh = D3DX.LoadMeshFromX(App.Path + "\Ene4.x", D3DXMESH_MANAGED, D3DDevice, Nothing, mtrlBuffer, NumMaterials)
D3DXMeshVertexBuffer8GetData Mesh, 0, Len(Interpol(0)) * Mesh.GetNumVertices, 0, KeyFrame4(0)
Set Mesh = D3DX.LoadMeshFromX(App.Path + "\Ene5.x", D3DXMESH_MANAGED, D3DDevice, Nothing, mtrlBuffer, NumMaterials)
D3DXMeshVertexBuffer8GetData Mesh, 0, Len(Interpol(0)) * Mesh.GetNumVertices, 0, KeyFrame5(0)
AnimLength(1) = 300
AnimLength(2) = 300
AnimLength(3) = 100
TurnPoints(5) = PI / 2
TurnPoints(6) = PI
TurnPoints(7) = PI * 5 / 4
TurnPoints(8) = PI
TurnPoints(9) = PI / 2
TurnPoints(1) = 0
TurnPoints(2) = PI * 7 / 4
TurnPoints(3) = 0
TurnPoints(4) = PI * 3 / 2
WayPoints(5) = MakeVector(-1.845205, 0, 2.014498)
WayPoints(6) = MakeVector(86.57822, 0, 2.272206)
WayPoints(7) = MakeVector(82.34792, 0, -53.47541)
WayPoints(8) = MakeVector(-0.3356083, 0, -136.6905)
WayPoints(9) = MakeVector(-2.144823, 0, -204.9477)
WayPoints(1) = MakeVector(173.6679, 0, -205.8015)
WayPoints(2) = MakeVector(174.1602, 0, -143.1451)
WayPoints(3) = MakeVector(94.5705, 0, -57.34747)
WayPoints(4) = MakeVector(84.67476, 0, 1.902351)
CurrWaypoint = 1
SHList(0).Col = &HCCFFFF00
SHList(1).Col = &HCCFFFF00
LookDir.Z = 1
Position = WayPoints(1)
D3DXMatrixRotationY ERotate, CAngle
D3DXVec3TransformCoord LookDir, MakeVector(0, 0, 1), ERotate
D3DXMatrixTranslation EMove, Position.X, Position.Y, Position.Z
D3DXMatrixMultiply EMatrix, ERotate, EMove
SoundShoot.Create App.Path + "\shoot.wav", -1000
tLife = Life
D3DXMatrixIdentity mIdentity
Mouth.X = 4.5
Mouth.Y = 6.864
Mouth.Z = 0.3
InitFlash
Spotted = False
PlayAnimation 1
LastUpdate = GetTickCount
End Function
Private Function InitFlash()
FList(0) = MakeFVertex(-FSize, 0, 0, 0, 1, &HFFFFFFFF)
FList(1) = MakeFVertex(0, 0, 0, 1, 1, &HFFFFFF)
FList(2) = MakeFVertex(0, FSize * 2, 0, 1, 0, &HFFFFFFFF)
FList(3) = MakeFVertex(FSize, 0, 0, 0, 1, &HFFFFFFFF)
FList(4) = MakeFVertex(0, 0, 0, 1, 1, &HFFFFFF)
FList(5) = MakeFVertex(0, FSize * 2, 0, 1, 0, &HFFFFFFFF)
FList(6) = MakeFVertex(-FSize, 0, 0, 0, 1, &HFFFFFFFF)
FList(7) = MakeFVertex(0, 0, 0, 1, 1, &HFFFFFF)
FList(8) = MakeFVertex(0, -FSize * 2, 0, 1, 0, &HFFFFFFFF)
FList(9) = MakeFVertex(FSize, 0, 0, 0, 1, &HFFFFFFFF)
FList(10) = MakeFVertex(0, 0, 0, 1, 1, &HFFFFFF)
FList(11) = MakeFVertex(0, -FSize * 2, 0, 1, 0, &HFFFFFFFF)
D3DXMatrixTranslation FlashTrans, Mouth.X, Mouth.Y, Mouth.Z
End Function
Public Function Render()
Dim Leng As Single, vOut As D3DVECTOR
Interval = (GetTickCount - LastUpdate) / 100
CTime = GetTickCount
If Death = False And GODI = 0 Then
D3DXVec3Subtract TV, MakeVector(EyePosition.X, EyePosition.Y + PlayerHeight, EyePosition.Z), Position
Leng = Sqr(TV.X * TV.X + TV.Y * TV.Y + TV.Z * TV.Z)
If Leng > 0 Then
TV.X = TV.X / Leng
TV.Y = TV.Y / Leng
TV.Z = TV.Z / Leng
If (mMesh.CollisionDetection(MakeVector(Position.X, Position.Y + 4, Position.Z), TV, Leng, vOut, Leng) = True) _
Or (DotProduct(TV, LookDir) < 0 And Spotted = False) Then
CurrAnim = 1
TTN = TTN + Interval / 100
If CurrWaypoint < 9 Then
D3DXVec3Lerp Position, WayPoints(CurrWaypoint), WayPoints(CurrWaypoint + 1), TTN
CAngle = TurnPoints(CurrWaypoint)
If TTN >= 1 Then
CurrWaypoint = CurrWaypoint + 1
TTN = 0
End If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -