Fun With Drones
The Drones are now functioning, complete with multiple explosion capabilities and sound FX! The sounds have been added using "OmegaWave". An easy to use freeware ocx from "Omega Techware". You can download it at the bottom of the page, just put the ocx file and the oca file in your System directory, and you'll be all set. Below is the Drone movement routine. The routine looks for active Drones, determines the direction they need to go based on their respective targets, checks where they will move next for obstacles, and then moves them until they reach their targets (if they get that far). Here's something fun to try if you download and run the code: Press "Pause", then flip through each ship with the Up/Down arrow buttons and select "Fire" until all ships are showing they have fired, and then press pause again to let them all go at once. If you have a bunch of asteroids on the screen, all the impacts are kinda neat to watch...
Note that this is a "Timer Routine" : it executes repeatedly
Private Sub DronePosition_Timer()
If Pause = True Then Exit Sub bail out
if the "Pause" button is pressed
For Ct = 1 To 50 flip through each of
the 50 drones to see if it's active and has a live target...
If Ship(Ship(Ct, 8), 9) = 1 And Drones(Ct, 4) =
1 Then destroy the drone if its target was destroyed...
Drones(Ct, 4) = 0:
'target already destroyed
PlayField.PSet (X1,
Y1), 0
ExX = Drones(Ct, 1)
ExY = Drones(Ct, 2)
StartExplosion
Update_Ship_GFX
End If
If Drones(Ct, 4) = 1 Then If the drone is active then...
' Active Drones
...transfer the drones location information to
other variables and determine which axis is the longest (X orY)...
X1 = Drones(Ct, 1): '
drone X position
Y1 = Drones(Ct, 2): '
drone Y position
X2 = Ship(Ship(Ct, 8),
1): ' get target ship X loaction
Y2 = Ship(Ship(Ct, 8),
2): ' get target ship Y location
If Abs(X1 - X2) >
Abs(Y1 - Y2) Then
DL
= Abs(X1 - X2)
Else
DL
= Abs(Y1 - Y2)
End If
If Int(DL) < 1 Then
...see if the drone reached its target...
'impact
Drones(Ct,
4) = 0
PlayField.PSet
(X1, Y1), 0: 'erase drone from screen
Wave.WaveFile
= App.Path + "/shiphit.wav"
Wave.PlayWave
DamagedShip
= Ship(Ct, 8)
Calculate_Ship_Damage
Update_Ship_GFX
Else
...otherwise, calculate the Increments values
to be added to each axis based on the distance of the longest axis...
XI
= (X2 - X1) / DL
YI
= (Y2 - Y1) / DL
PlayField.PSet
(X1, Y1), 0: 'erase drone from screen before re-drawing
...add
the "X" and "Y" increment values that were calculated above...
Drones(Ct,
1) = Drones(Ct, 1) + XI
Drones(Ct,
2) = Drones(Ct, 2) + YI
...see
if the drone ran into anything other than: empty space, a RED pixel, a GREEN pixel, or a
PURPLE pixel...
P
= PlayField.Point(Drones(Ct, 1), Drones(Ct, 2))
If
P = 0 Or P = 255 Or P = RGB(0, 255, 0) Or P = 16726271 Then
...if
nothing was hit, then move to the next location...
PlayField.PSet
(Drones(Ct, 1), Drones(Ct, 2)), RGB(255, 55, 255)
Else
...if
it DID hit something ---> blow it up!
'drone
hit something before reaching its target
Drones(Ct,
4) = 0
ExX
= Drones(Ct, 1)
ExY
= Drones(Ct, 2)
StartExplosion
Update_Ship_GFX
End
If
End If
End If
Next Ct
End Sub
Clear as mud? Here are the next couple downloads: