-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclsAI.cls
224 lines (171 loc) · 5.39 KB
/
clsAI.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsAI"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Rem *** The FSM-AI class
Rem *** Purpose: Create enemies, determine ships, _
bunkers and other objects behavior
Private m_lAIUpdateTime As Long ' update AI delay
Private lCSTime1 As Long ' create enemy delay
Private lCSTime2 As Long
Private lCSTime3 As Long
Private lCSTime4 As Long
Private bFlag1 As Boolean
Private bytLevelState As Byte
Private m_bytlevel As Byte
' //////////////////////////////////////////////////////////
' //// main AI refreshing
' //////////////////////////////////////////////////////////
Public Sub _
Update()
Static lUBTime As Long ' update bunkers counter
Dim cn As Integer
If (m_lAIUpdateTime < GetTicks) Then
m_lAIUpdateTime = GetTicks + FPS_AI
Select Case m_bytlevel
' --- level 0 --- the Demo level ------------
Case 0
' see if enemy1 should be created
'If (GetTicks > lCSTime1) Then
'lCSTime1 = GetTicks + nGetRnd(2500, 8000)
' lCSTime1 = GetTicks + nGetRnd(3500, 5000)
' Call CreateEnemy(ST_LRSNEAKY)
'End If
'If (GetTicks > lCSTime2) Then
' lCSTime2 = GetTicks + nGetRnd(3000, 4500)
' Call CreateEnemy(ST_SEVENTHFOX)
'End If
If (GetTicks > lCSTime2) Then
lCSTime2 = GetTicks + nGetRnd(1200, 5500)
Call CreateEnemy(ST_PARTICLEBEAST)
End If
' --- level 1 --- the fast strike -----------
Case 1
Select Case bytLevelState
' phase 1 - the first encounter
Case 1
If (GetTicks > lCSTime1) Then
For cn = 0 To 3
Call CreateEnemy(ST_LRSNEAKY)
Call CreateEnemy(ST_SEVENTHFOX)
Next
' activate phase 2
bytLevelState = 2
End If
' phase 2 - random slayers
Case 2
' see if enemy1 should be created
If (GetTicks > lCSTime2) Then
lCSTime2 = GetTicks + nGetRnd(3800, 4100)
Call CreateEnemy(ST_LRSNEAKY)
End If
' see if enemy2 should be created
If (GetTicks > lCSTime3) Then
lCSTime3 = GetTicks + nGetRnd(2500, 2800)
Call CreateEnemy(ST_SEVENTHFOX)
End If
End Select
' --- level 2 --- meteor shower -------------
Case 2
'...
' --- level 3 --- big homeys ----------------
Case 3
'...
' --- level 4 --- defend the station --------
Case 4
'...
' --- level 5 --- fight for existance -------
Case 5
'...
Case Else
Exit Sub
End Select
End If
End Sub
' //////////////////////////////////////////////////////////
' //// Creates random enemy
' //////////////////////////////////////////////////////////
Public Sub _
SetupLevel(bytGameLevel As Byte)
' reset vars
m_lAIUpdateTime = 0
lCSTime1 = 0
lCSTime2 = 0
lCSTime3 = 0
lCSTime4 = 0
' set current mission
m_bytlevel = bytGameLevel
' set default levelstate
bytLevelState = 1
Select Case m_bytlevel
Case 0
'...
Case 1
lCSTime1 = 5000 + GetTicks
bytLevelState = 1
Case 2
'...
Case 3
'...
Case 4
'...
Case 5
'...
End Select
End Sub
' //////////////////////////////////////////////////////////
' //// Creates random enemy
' //////////////////////////////////////////////////////////
Private Sub _
CreateEnemy(bytEnemy As Byte)
' --------------!
'Static ar As Integer
'If ar > 2 Then Exit Sub
'ar = ar + 1
' !--------------
Dim cn As Integer
Dim nDirX As Integer
Dim xPos As Integer, yPos As Integer
Dim nRandMin As Integer, nRandMax As Integer
' get random appearance position
If nGetRnd(0, 1) = 0 Then
nDirX = nGetRnd(20, 200) 'real
Else
nDirX = nGetRnd(SCREEN_PIXEL_WIDTH - 100, SCREEN_PIXEL_WIDTH)
'nDirX = nGetRnd(2160, 2560)
End If
yPos = nGetRnd(0, VISIBLE_AREA_CY - 150)
' get type of ship to appear
If nGetRnd(0, 100) < 25 Then ' create close - ship
nRandMin = 3
nRandMax = SHIPS
Else ' create far ship
nRandMin = 0
nRandMax = 2
End If
' check for empty enemy class
Do While cn < MAX_ENEMIES
If (Not cShip(cn).GetVisible) Then
'cShip(cn).CreateShip nDirX, yPos, ST_CARRIER1 '_
If (bytEnemy <> 255) Then
Call cShip(cn).CreateShip(nDirX, yPos, bytEnemy)
Else
' create random ship
Call cShip(cn).CreateShip(nDirX, yPos, nGetRnd(0, SHIPS))
End If
Exit Do ' exit here for creation has finished
End If
cn = cn + 1
Loop
' Debug.Print "ship n:" & cn & " pos. app: " & nDirX
End Sub