Dim Cars
Dim blnMoveL As Boolean
Dim blnMoveR As Boolean
Dim blnMoveU As Boolean
Dim blnMoveD As Boolean
Dim blnPlay As Boolean
Dim mintPos As Integer
Dim mintLives As Integer
Dim mintCars As Integer
Dim mintLevel As Integer
Const mintFrog As Integer = 480 'Height and Width of the frog image
Option Explicit
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'*snip (this code works fine, it's just the code to move the frog image)*
CheckDeath 'Calls the CheckDeath function
If imgFrog.Top = 0 Then AdvanceLevel 'Calls the AdvanceLevel function when frog
'reaches the top
End Sub
Private Sub tmrCar_Timer()
'Moves the "cars" around
On Error GoTo Finish
For Cars = 0 To mintCars
shaCar(Cars).Left = shaCar(Cars).Left + 480
If shaCar(Cars).Left > frmMain.Width Then
mintPos = shaCar(Cars).Left - frmMain.Width
If mintPos >= 0 Then
shaCar(Cars).Left = -(mintFrog)
End If
End If
Next Cars
CheckDeath
Finish:
End Sub
Private Function AdvanceLevel()
'Makes the game progressively harder
Dim intTimer As Integer
intTimer = tmrCar.Interval
intTimer = intTimer - 100
If intTimer = 0 Then
MsgBox "You've beaten the game! You are a true 'Frogger' Master!", vbExclamation, "Congratulations!"
blnPlay = False
tmrCar.Enabled = False
Else
mintLevel = mintLevel + 1
mintCars = mintCars + 2
'Above line is the line that causes the problem I believe - when I comment it out the program works fine
tmrCar.Interval = intTimer
MsgBox "Proceeding to level " & mintLevel, vbOKOnly, "Level passed!"
End If
lblLvl = mintLevel
StartPos 'Calls the StartPos function
End Function
Private Function StartPos()
'Moves the frog image to the starting position
imgFrog.Left = 4800
imgFrog.Top = 4800
End Function
Private Function CheckDeath()
'Checks to see if the frog got ran over
Dim Cars2
On Error GoTo Finish
For Cars2 = 0 To mintCars
If shaCar(Cars2).Left = imgFrog.Left And shaCar(Cars2).Top = imgFrog.Top Then
mintLives = mintLives - 1
If mintLives < 0 Then
MsgBox "Game over!"
blnPlay = False
Else
MsgBox "You died!" & vbCrLf & mintLives & " lives left!", vbCritical, "Splat!"
StartPos 'Calls the StartPos function
lblLives = mintLives
End If
End If
Next Cars2
Finish:
End Function