📄 cenemy.cls
字号:
Else
D3DXVec3Lerp Position, WayPoints(CurrWaypoint), WayPoints(1), TTN
CAngle = TurnPoints(CurrWaypoint)
If TTN >= 1 Then
CurrWaypoint = 1
TTN = 0
End If
End If
D3DXMatrixRotationY ERotate, CAngle
D3DXVec3TransformCoord LookDir, MakeVector(0, 0, 1), ERotate
D3DXMatrixTranslation EMove, Position.X, Position.Y, Position.Z
D3DXMatrixMultiply EMatrix, ERotate, EMove
Spotted = False
Else
SoundShoot.SetVolume -Leng * 10
D3DXVec3Normalize TV, MakeVector(TV.X, 0, TV.Z)
Leng = DotProduct(TV, MakeVector(0, 0, 1))
Leng = Asin(Sqr(1 - Leng * Leng))
If TV.X <= 0 Then Leng = 2 * PI - Leng
If TV.Z <= 0 Then Leng = PI - Leng
CAngle = 0
D3DXMatrixRotationY ERotate, Leng
D3DXVec3TransformCoord LookDir, MakeVector(0, 0, 1), ERotate
D3DXMatrixTranslation EMove, Position.X, Position.Y, Position.Z
D3DXMatrixMultiply EMatrix, ERotate, EMove
If CurrAnim = 1 Then
PlayAnimation 3
Spotted = True
End If
If ShootCool <= 0 Then
SoundShoot.PlaySound False
HitPlayer
ShootCool = CDown
SHList(0).Pos = MakeVector(Position.X + LookDir.X * Mouth.X + LookDir.Z * Mouth.Z, _
Position.Y + Mouth.Y, _
Position.Z + LookDir.Z * Mouth.X - LookDir.X * Mouth.Z)
SHList(1).Pos = MakeVector(EyePosition.X, EyePosition.Y + PlayerHeight - 1, EyePosition.Z)
SVisible = 3
D3DXMatrixTranslation FlashTrans, SHList(0).Pos.X, SHList(0).Pos.Y, SHList(0).Pos.Z
D3DXMatrixMultiply FlashTrans, ERotate, FlashTrans
Else
ShootCool = ShootCool - (CTime - LastUpdate)
End If
End If
End If
End If
If CurrAnim <> 0 Then
Select Case CurrAnim
Case 1
Leng = (CTime - StartAnim) / AnimLength(1)
If Leng > 1 Then Leng = 1
If Infin = 0 Then
For k = 0 To Mesh.GetNumVertices
D3DXVec3Lerp TempV, _
MakeVector(KeyFrame2(k).X, KeyFrame2(k).Y, KeyFrame2(k).Z), _
MakeVector(KeyFrame3(k).X, KeyFrame3(k).Y, KeyFrame3(k).Z), _
(CTime - StartAnim) / AnimLength(1)
Interpol(k).X = TempV.X
Interpol(k).Y = TempV.Y
Interpol(k).Z = TempV.Z
Next k
Else
For k = 0 To Mesh.GetNumVertices
D3DXVec3Lerp TempV, _
MakeVector(KeyFrame3(k).X, KeyFrame3(k).Y, KeyFrame3(k).Z), _
MakeVector(KeyFrame2(k).X, KeyFrame2(k).Y, KeyFrame2(k).Z), _
(CTime - StartAnim) / AnimLength(1)
Interpol(k).X = TempV.X
Interpol(k).Y = TempV.Y
Interpol(k).Z = TempV.Z
Next k
End If
If Leng = 1 Then
StartAnim = GetTickCount
Infin = Infin Xor 1
End If
Case 2
Leng = (CTime - StartAnim) / AnimLength(2)
If Leng > 1 Then Leng = 1
For k = 0 To Mesh.GetNumVertices
D3DXVec3Lerp TempV, _
MakeVector(KeyFrame1(k).X, KeyFrame1(k).Y, KeyFrame1(k).Z), _
MakeVector(KeyFrame4(k).X, KeyFrame4(k).Y, KeyFrame4(k).Z), _
Leng
Interpol(k).X = TempV.X
Interpol(k).Y = TempV.Y
Interpol(k).Z = TempV.Z
Next k
If Leng = 1 Then
CurrAnim = 0
End If
Case 3
Leng = (CTime - StartAnim) / AnimLength(3)
If Leng > 1 Then Leng = 1
For k = 0 To Mesh.GetNumVertices
D3DXVec3Lerp TempV, _
MakeVector(KeyFrame1(k).X, KeyFrame1(k).Y, KeyFrame1(k).Z), _
MakeVector(KeyFrame5(k).X, KeyFrame5(k).Y, KeyFrame5(k).Z), _
Leng
Interpol(k).X = TempV.X
Interpol(k).Y = TempV.Y
Interpol(k).Z = TempV.Z
Next k
If Leng = 1 Then
CurrAnim = 0
End If
End Select
D3DXMeshVertexBuffer8SetData Mesh, 0, Len(Interpol(0)) * Mesh.GetNumVertices, 0, Interpol(0)
End If
D3DDevice.SetTransform D3DTS_WORLD, EMatrix
For k = 0 To NumMaterials - 1
D3DDevice.SetMaterial Materials(k)
D3DDevice.SetTexture 0, Textures(k)
Mesh.DrawSubset k
Next k
If SVisible > 0 Then
DrawShot
DrawFlash
SVisible = SVisible - 1
End If
LastUpdate = GetTickCount
End Function
Public Function SpotEnemy()
Spotted = True
End Function
Public Function DrawShot()
D3DDevice.SetRenderState D3DRS_LIGHTING, 0
D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, 1
D3DDevice.SetTransform D3DTS_WORLD, mIdentity
D3DDevice.SetTexture 0, Nothing
D3DDevice.SetVertexShader FVFCH
D3DDevice.DrawPrimitiveUP D3DPT_LINELIST, 1, SHList(0), Len(SHList(0))
D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, 0
D3DDevice.SetRenderState D3DRS_LIGHTING, 1
End Function
Public Function DrawFlash()
D3DDevice.SetRenderState D3DRS_LIGHTING, 0
D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, 1
D3DDevice.SetTransform D3DTS_WORLD, FlashTrans
D3DDevice.SetTexture 0, FlashTexture
D3DDevice.SetVertexShader FVFF
D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLELIST, 4, FList(0), Len(FList(0))
D3DDevice.SetRenderState D3DRS_ALPHABLENDENABLE, 0
D3DDevice.SetRenderState D3DRS_LIGHTING, 1
End Function
Public Function MoveRot(ForW As Single, SideW As Single, aY As Single)
CAngle = CAngle + aY
If CAngle < 0 Then CAngle = CAngle + 2 * PI
If CAngle > 2 * PI Then CAngle = CAngle - 2 * PI
D3DXMatrixRotationY ERotate, CAngle
D3DXVec3TransformCoord LookDir, MakeVector(0, 0, 1), ERotate
D3DXMatrixTranslation EMove, LookDir.X * ForW + Position.X, Position.Y, LookDir.Z * ForW + Position.Z
D3DXVec3TransformCoord Position, MakeVector(0, 0, 0), EMove
D3DXMatrixMultiply EMatrix, ERotate, EMove
End Function
Public Function Collision(StartPo As D3DVECTOR, Dir As D3DVECTOR, mDist As Single, Hit As D3DVECTOR) As Boolean
Dim Hits As Long, PU As Single, PV As Single, Dist As Single, nHits As Long, Ind As Long
Dim StartP As D3DVECTOR, TempM As D3DMATRIX
D3DXMatrixTranslation TempM, -Position.X, -Position.Y, -Position.Z
D3DXVec3TransformCoord StartP, StartPo, TempM
D3DX.Intersect Mesh, StartP, Dir, Hits, Ind, PU, PV, Dist, nHits
If Hits = 1 Then
If mDist >= Dist Then
Collision = True
Hit = MakeVector(StartPo.X + Dir.X * Dist, StartPo.Y + Dir.Y * Dist, StartPo.Z + Dir.Z * Dist)
Exit Function
End If
End If
Collision = False
End Function
Public Function PlayAnimation(NumAn As Integer)
If Death = False Then
If NumAn = 2 Then Death = True
StartAnim = GetTickCount
CurrAnim = NumAn
End If
End Function
Public Function IsHit()
If tLife <= 1 Then
PlayAnimation 2
tLife = 0
GODI = 2
Else
tLife = tLife - 1
End If
End Function
Public Function Revive()
Death = False
CurrAnim = 1
tLife = Life
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -