Option Explicit
Dim BulletON(4) As Boolean
Dim points As Double
Dim i As Integer
Private Sub Cmdnew_Click()
Cmdnew.Visible = False
lblpoints = 0
lbllives.Caption = 2
lblcallsign.Visible = True
lblpointlabel.Visible = True
lblpoints.Visible = True
lblliveslabel.Visible = True
lbllives.Visible = True
imgShip.Visible = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Call GotKey(KeyCode)
End Sub
Private Sub Form_Load()
Dim name As String
name = InputBox("What is your callsign?")
lblcallsign.Caption = "Callsign: " + name
lblcallsign.Visible = False
lblpointlabel.Visible = False
lblpoints.Visible = False
lblliveslabel.Visible = False
lbllives.Visible = False
imgship.Visible = False
For i = 0 To 4
linBullet(i).Visible = False
Next i
End Sub
Public Function GotKey(KeyCode As Integer)
If KeyCode = vbKeyDown Then
If imgShip.Top > 5000 Then
imgShip.Move imgShip.Left, imgShip.Top + 0
Else
imgShip.Move imgShip.Left, imgShip.Top + 60
End If
End If
If KeyCode = vbKeyUp Then
If imgShip.Top < 4000 Then
imgShip.Move imgShip.Left, imgShip.Top - 0
Else
imgShip.Move imgShip.Left, imgShip.Top - 60
End If
End If
If KeyCode = vbKeyLeft Then
If imgShip.Left < 0 Then
imgShip.Move imgShip.Left - 0
Else
imgShip.Move imgShip.Left - 60
End If
End If
If KeyCode = vbKeyRight Then
If imgShip.Left > 6500 Then
imgShip.Move imgShip.Left + 0
Else
imgShip.Move imgShip.Left + 60
End If
End If
'=======================
'===I ADDED THIS CODE===
'=======================
Dim NextBullet As Integer
NextBullet = -1
For i = 0 To 4 'This sees which bullet is next ready
If BulletON(i) = False Then NextBullet = i
Next i
If KeyCode = vbKeySpace And NextBullet <> -1 Then
BulletON(NextBullet) = True
linBullet(NextBullet).Visible = True
linBullet(NextBullet).X1 = imgShip.Left + (imgShip.Width / 2)
linBullet(NextBullet).X2 = imgShip.Left + (imgShip.Width / 2)
linBullet(NextBullet).Y1 = imgShip.Top + 250
linBullet(NextBullet).Y2 = linBullet(NextBullet).Y1 + 240
End If
End Function
Public Function MoveBullet(bullet As Integer)
For i = 0 To 4 '(4 is just the number of bullets
'I chose you may even want a varible)
If BulletON(i) = True Then
linBullet(i).Y1 = linBullet(i).Y1 - 100 'again 100 is arbitrary
linBullet(i).Y2 = linBullet(i).Y1 + 240 ' 240 is just how long the line is
If linBullet(i).Y2 <= 0 Then BulletON(i) = False
End If
Next i
End Function
Private Sub imgship_KeyDown(KeyCode As Integer, Shift As Integer)
Call GotKey(KeyCode)
End Sub
Private Sub Timer1_Timer()
For i = 0 To 4
If BulletON(i) = True Then Call MoveBullet(i)
Next i
End Sub