Link to home
Start Free TrialLog in
Avatar of n-generation
n-generation

asked on

moving cars and logs in array.

I am currently using a game to creat a frogger program and so far I produced some moving cars and logs across the screen. I can get the cars and logs to go across the screen but after awhile the longer logs will cramp up with the shorter ones and the trucks will overlap with the small cars.  And I feel this isn't the most efficicient method in doing this.  Can anyone just read through the code and tell me how I can improve on this?

Thanks!

Option Explicit

Dim i As Integer
Dim j As Integer
Dim CarSpeed(8) As Integer
Dim LogSpeed(10) As Integer

Sub LoadGame()

For i = 0 To 3: CarSpeed(i) = 70: Next i
For i = 4 To 8: CarSpeed(i) = -80: Next i
For i = 0 To 2: LogSpeed(i) = 30: Next i
For i = 3 To 5: LogSpeed(i) = -40: Next i
For i = 6 To 8: LogSpeed(i) = 35: Next i

TmrRoad.Enabled = True
TmrRiver.Enabled = True

End Sub

Private Sub Form_Load()

LoadGame

End Sub
Private Sub TmrRiver_Timer()
    For j = 0 To 8
        ImgLog(j).Left = ImgLog(j).Left + LogSpeed(j)
       
            If ImgLog(j).Left > frmFrogger.ScaleWidth Then
           
                ImgLog(j).Left = 0 - ImgLog(j).Width
               
            End If
           
            If ImgLog(j).Left < (0 - ImgLog(j).Width) Then
               
                ImgLog(j).Left = frmFrogger.ScaleWidth
               
            End If
    Next j
End Sub

Private Sub TmrRoad_Timer()

    For j = 0 To 8
       
        ImgCar(j).Left = ImgCar(j).Left + CarSpeed(j)
       
            If ImgCar(j).Left > frmFrogger.ScaleWidth Then
               
                ImgCar(j).Left = 0 - ImgCar(j).Width
           
            End If
           
            If ImgCar(j).Left < (0 - ImgCar(j).Width) Then
               
                ImgCar(j).Left = frmFrogger.ScaleWidth
           
            End If
    Next j
   
End Sub
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also unsure why you are processing with two separate timers.