@@ -11,8 +11,8 @@ Thread.InitializationDelay = 3
1111ExitUpdateFrame = False
1212EnemyShipLabel2 = ""
1313EnemyShipLabel3 = ""
14- PlayerSpeed = 3
15- BulletSpeed = 10
14+ PlayerSpeed = 7
15+ BulletSpeed = 15
1616
1717' -------------------------------------------------------------------
1818' Using ListBox to add and remove items has better performance that SB array.
@@ -50,12 +50,14 @@ Timer.Tick = UpdateFrame
5050CreateEnemies()
5151
5252
53+ ' ------------------------------------------------
5354Sub CreateEnemies()
5455 For i = 1 To 3
5556 CreateEnemy()
5657 Next
5758EndSub
5859
60+ ' ------------------------------------------------
5961Sub CreateEnemy()
6062 lblEnemy = GetHiddenLabel(Enemies)
6163 If lblEnemy = "" Then
@@ -65,7 +67,7 @@ Sub CreateEnemy()
6567 0
6668 )
6769 lblEnemy.Tag = {
68- Math.Rnd(-15, 15), ' Speed X
70+ Math.Rnd(-15, 15), ' Speed X
6971 Math.Rnd(2, 4), ' Speed y
7072 Math.Rnd(20, 50) ' Bullet frequency
7173 }
@@ -76,6 +78,9 @@ Sub CreateEnemy()
7678 EndIf
7779EndSub
7880
81+
82+ ' --------------------------------------------------
83+
7984Function CreateShip(image, x, y)
8085 ship = Controls.AddLabel("", x, y)
8186 ship.Image = image
@@ -84,6 +89,7 @@ Function CreateShip(image, x, y)
8489 Return ship
8590EndFunction
8691
92+ ' --------------------------------------------------
8793Sub UpdateFrame()
8894 MovePlayerShip()
8995 If ExitUpdateFrame Then
@@ -98,16 +104,22 @@ Sub UpdateFrame()
98104 EndIf
99105
100106 Thread.SubToRun = MoveBullets
107+ Thread.SubToRun = MoveEnemyBullets
108+ Thread.SubToRun = MoveEnemies
101109
110+ ExitUpdateFrame = False
111+ EndSub
112+ ' -----------------------------------------------------------------
113+
114+ Sub MoveEnemies()
102115 For i = 1 To Enemies.Count
103116 EnemyShipLabel = Enemies[i]
104117 If EnemyShipLabel.Visible Then
105118 Thread.SubToRun = MoveEnemy
106119 EndIf
107120 Next
108-
109- ExitUpdateFrame = False
110121EndSub
122+ ' -----------------------------------------------------------------
111123
112124Sub MoveEnemy()
113125 lblEnemy = EnemyShipLabel
@@ -149,6 +161,7 @@ Sub MoveEnemy()
149161 EnemyShipLabel3 = lblEnemy
150162 Thread.SubToRun = CheckEnemyAndBuulets
151163EndSub
164+ ' -----------------------------------------------------------------
152165
153166Sub FireEnemyBullet()
154167 lblEnemy = EnemyShipLabel2
@@ -166,6 +179,7 @@ Sub FireEnemyBullet()
166179 lblBullet.Visible = True
167180 EndIf
168181EndSub
182+ ' -----------------------------------------------------------------
169183
170184Sub CheckEnemyAndBuulets()
171185 lblEnemy = EnemyShipLabel3
@@ -176,6 +190,7 @@ Sub CheckEnemyAndBuulets()
176190 EndIf
177191EndSub
178192
193+ ' -----------------------------------------------------------------
179194Sub MoveBullets()
180195 For i = Bullets.Count To 1 Step -1
181196 lblBullet = Bullets[i]
@@ -186,7 +201,10 @@ Sub MoveBullets()
186201 EndIf
187202 EndIf
188203 Next
189-
204+ EndSub
205+
206+ ' -----------------------------------------------------------------
207+ Sub MoveEnemyBullets()
190208 ForEach lblBullet In EnemyBullets
191209 If lblBullet.Visible Then
192210 lblBullet.Top = lblBullet.Top + BulletSpeed
@@ -205,7 +223,7 @@ Sub MoveBullets()
205223 EndIf
206224 Next
207225EndSub
208-
226+ ' -----------------------------------------------------------
209227Function CollideWithPlayerBullets(lblEnemy)
210228 ForEach lblBullet In Bullets
211229 If lblBullet.Visible Then
@@ -218,6 +236,7 @@ Function CollideWithPlayerBullets(lblEnemy)
218236 Return False
219237EndFunction
220238
239+ ' -----------------------------------------------------------
221240Function BulletHitsEnemy(lblBullet, lblEnemy)
222241 If ImageList.Collide(
223242 lblBullet.Left, lblBullet.Top, UpBulletImage,
@@ -232,6 +251,7 @@ Function BulletHitsEnemy(lblBullet, lblEnemy)
232251 Return False
233252EndFunction
234253
254+ ' --------------------------------------------------
235255Function EnemyHitsPlayer(lblEnemy)
236256 If lblEnemy.Tag = "" Then
237257 image = DownBulletImage
@@ -253,6 +273,7 @@ Function EnemyHitsPlayer(lblEnemy)
253273 Return False
254274EndFunction
255275
276+ ' --------------------------------------------------
256277Sub GraphicsWindow_KeyDown()
257278 k = Keyboard.LastKey
258279
@@ -275,6 +296,7 @@ Sub GraphicsWindow_KeyDown()
275296 EndIf
276297EndSub
277298
299+ ' ------------------------------------------------
278300Sub MovePlayerShip()
279301 If Keyboard.IsKeyDown(Keys.Left) Then
280302 PlayerShip.Left = PlayerShip.Left - PlayerSpeed
@@ -302,6 +324,7 @@ Sub MovePlayerShip()
302324 EndIf
303325EndSub
304326
327+ ' ------------------------------------------------
305328Function GetHiddenLabel(arr)
306329 ForEach _label In arr
307330 If _label.Visible = False Then
0 commit comments