📄 bullettype.bas
字号:
Attribute VB_Name = "ModBulletType"
Option Explicit
'''''产生一般的类型
Public Sub CreateBullet(ByVal BulType As Byte, ByVal BulStartX As Single, ByVal BulStartY As Single, FireFps As Integer) '注意firefps 是传地址,因为在该模块中会改动*.CurFireFps ', ByVal IsObjRotate As Boolean, ByVal TypeMove As Byte)
Dim IndexBul As Byte
Dim InitSpeed As Single
Dim CountF As Byte
'Dim FireType As Byte
'If FireFps > 0 And LoadBul(BulType).TypeMove < 9 Then Exit Sub
' type 8 后为特殊类型,必须限制进入
For IndexBul = CurBul + 1 To MaxBul '如果把for next放到里面,虽速度更快,但比较烦琐
If PlayBul(IndexBul).IndexR = 0 Then
'PlayBul(IndexBul).IndexR = BulType
'FireType = LoadBul(BulType).TypeMove
InitSpeed = CSng(LoadBul(BulType).SpeedInit)
InitSpeed = IIf((LoadBul(BulType).SpeedInit = 0), Rnd * 2 + 3, InitSpeed)
With PlayBul(IndexBul)
.CurX = BulStartX - LoadBul(BulType).Width \ 2
.CurY = BulStartY - LoadBul(BulType).Height \ 2
.IndexR = BulType '******************
.IsRotate = LoadBul(BulType).IsRotate
.CurDelay = 0
Select Case LoadBul(BulType).TypeMove
Case 0
.CurSpeedX = 0
.CurSpeedY = InitSpeed
Exit For
Case 1
.CurSpeedX = InitSpeed * (CountF - 1) \ 2
.CurSpeedY = InitSpeed
If CountF = 2 Then CountF = 200: Exit For
CountF = CountF + 2
Case 2
.CurSpeedX = InitSpeed * (CountF - 1) \ 2
.CurSpeedY = InitSpeed
If CountF = 2 Then CountF = 200: Exit For
CountF = CountF + 1
Case 3
.CurSpeedX = InitSpeed * Cos(CF(CountF * 30))
.CurSpeedY = InitSpeed * Sin(CF(CountF * 30))
If CountF = 11 Then CountF = 200: Exit For
CountF = CountF + 1
Case 4
.CurSpeedX = InitSpeed * Cos(CF(CountF * 18 - 9))
.CurSpeedY = InitSpeed * Sin(CF(CountF * 18 - 9))
CountF = CountF + 1
If CountF = 20 Then CountF = 200: Exit For
Case 5
.CurSpeedX = InitSpeed * Cos(CF(CountF * 18 - 9))
.CurSpeedY = InitSpeed * Sin(CF(CountF * 18 - 9))
If CountF Mod 2 = 0 Then
.CurSpeedX = .CurSpeedX * 1.2
.CurSpeedY = .CurSpeedY * 1.2
End If
CountF = CountF + 1
If CountF = 20 Then CountF = 200: Exit For
'Case 6
Case 6
.CurSpeedX = InitSpeed * Tan(CF(CountF * 8 - 32))
.CurSpeedY = InitSpeed
CountF = CountF + 1
If CountF = 9 Then CountF = 200: Exit For
Case 7
.CurSpeedX = InitSpeed * Cos(CF(CountF * 8 + 58))
.CurSpeedY = InitSpeed * Sin(CF(CountF * 8 + 58))
CountF = CountF + 1
If CountF = 9 Then CountF = 200: Exit For
Case 8
.CurSpeedX = 0
.CurSpeedY = InitSpeed * (1 + CountF / 3)
CountF = CountF + 1
If CountF = 6 Then CountF = 200: Exit For
''从9 开始为特殊类型,会影响前面的类型,必须限制进入
Case 9
If SoundBul = 0 And FireFps = 0 Then SoundBul = 1: GameSound.PlaySound CStr(LoadBul(BulType).Sound), 1
'If FireFps Mod 3 = 0 Then
.CurSpeedX = InitSpeed * Sin(CF(FireFps * 30))
.CurSpeedY = InitSpeed * Cos(CF(FireFps * 30))
'End If
FireFps = IIf(FireFps > 11, 0, FireFps + 1)
Exit For
Case Else: Exit Sub
End Select
End With
End If
Next IndexBul
'后面可能还有,所以用exit for
If SoundBul = 0 And CountF = 200 Then SoundBul = 1: GameSound.PlaySound CStr(LoadBul(BulType).Sound), 1
CurBul = IndexBul
End Sub
'''产生旋转的类型 ''该用bultype 'object的中心
Public Sub CreateRotateBullet(ByVal WhPlayer As Byte, ByVal FireType As Integer, ByVal FireSeatX0 As Single, ByVal FireSeatY0 As Single)
Dim IndexBul As Byte
Dim InitSpeed As Single
Dim ErrX As Single
Dim ErrY As Single
Dim CountF As Byte
Dim LastX As Single
Dim LastY As Single
Dim LastSpeedX As Single
Dim LastSpeedY As Single
Dim IsC As Boolean
For IndexBul = CurBul + 1 To MaxBul
If PlayBul(IndexBul).IndexR = 0 And (Not IsC) Then
InitSpeed = CSng(LoadBul(FireType).SpeedInit)
InitSpeed = IIf((LoadBul(FireType).SpeedInit = 0), Rnd * 2 + 3, InitSpeed)
ErrX = CurMyXp(WhPlayer) - FireSeatX0
ErrY = CurMyYp(WhPlayer) - FireSeatY0
LastX = FireSeatX0 - LoadBul(FireType).Width \ 2
LastY = FireSeatY0 - LoadBul(FireType).Height \ 2
With PlayBul(IndexBul)
''''.IndexR = 0 ' FireType
.CurDelay = 0
.IsRotate = LoadBul(FireType).IsRotate
If ErrY = 0 Then
.CurSpeedX = InitSpeed * Sgn(ErrX)
.CurSpeedY = 0
ElseIf Abs(ErrX / ErrY) > 0.1 And Abs(ErrX / ErrY) < 10 Then
.CurSpeedX = InitSpeed * ErrX / Sqr(ErrX ^ 2 + ErrY ^ 2)
.CurSpeedY = .CurSpeedX * ErrY / ErrX
ElseIf Abs(ErrX) > Abs(ErrY) Then
.CurSpeedY = 0
.CurSpeedX = InitSpeed * Sgn(ErrX)
Else
.CurSpeedX = 0
.CurSpeedY = InitSpeed * Sgn(ErrY)
End If
LastSpeedX = .CurSpeedX
LastSpeedY = .CurSpeedY
IsC = True
End With
'Exit For
End If
If PlayBul(IndexBul).IndexR = 0 Then
With PlayBul(IndexBul)
.IndexR = FireType
.CurX = LastX
.CurY = LastY
Select Case LoadBul(FireType).TypeMove
Case 0, 1
.CurSpeedX = LastSpeedX
.CurSpeedY = LastSpeedY
If Abs(.CurSpeedX) < 1 And Abs(.CurSpeedY) < 1 Then .CurSpeedY = 2
Exit For
Case 2
CountF = CountF + 1
.CurSpeedX = LastSpeedX
Select Case CountF
Case 1
.CurSpeedY = LastSpeedY
Case 2
.CurSpeedY = LastSpeedY - Sgn(LastSpeedY)
If Abs(.CurSpeedY) < 1 Then .CurSpeedY = LastSpeedY
Case 3
.CurSpeedY = LastSpeedY + Sgn(LastSpeedY)
End Select
If CountF = 3 Then Exit For
Case 3
CountF = CountF + 1
.CurSpeedY = LastSpeedY
Select Case CountF
Case 1
.CurSpeedX = LastSpeedX
Case 2
.CurSpeedX = LastSpeedX - Sgn(LastSpeedX)
If Abs(.CurSpeedX) < 1 Then .CurSpeedX = Sgn(LastSpeedX)
Case 3
.CurSpeedX = LastSpeedX + Sgn(LastSpeedX)
End Select
If CountF = 3 Then Exit For
Case 4
CountF = CountF + 1
Select Case CountF
Case 1
.CurSpeedX = LastSpeedX
.CurSpeedY = LastSpeedY
Case 2
.CurSpeedX = LastSpeedX - Sgn(LastSpeedX)
If Abs(.CurSpeedX) < 1 Then .CurSpeedX = Sgn(LastSpeedX)
.CurSpeedY = LastSpeedY + Sgn(LastSpeedY)
Case 3
.CurSpeedX = LastSpeedX + Sgn(LastSpeedX)
.CurSpeedY = LastSpeedY - Sgn(LastSpeedY)
If Abs(.CurSpeedY) < 1 Then .CurSpeedY = Sgn(LastSpeedY)
End Select
If CountF = 3 Then Exit For
Case Else: Exit Sub
End Select
End With
End If
Next IndexBul
CurBul = IndexBul
End Sub
Public Sub CreatePackage(ByVal PacType As Byte, ByVal PacStartX As Single, ByVal PacStartY As Single)
Dim IndexPac As Byte
'dim
For IndexPac = CurPac + 1 To MaxPac
With PlayPac(IndexPac)
If .IndexR = 0 Then
.IndexR = PacType
.CurX = PacStartX
.CurY = PacStartY
.CurSpeedX = Sgn(Rnd * 2 - 1.05) * 2
.CurSpeedY = Sgn(Rnd * 2 - 1.05) * 2
.CurAngle = 0
.CurFps = 0
.CurDelay = 0
.CurTotalFps = 0
CurPac = IndexPac: Exit Sub
End If
End With
Next IndexPac
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -