Solved

# moving cars and logs in array.

Posted on 2003-03-18
Medium Priority
199 Views
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

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

TmrRiver.Enabled = True

End Sub

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

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
0
Question by:n-generation
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 38

Accepted Solution

PaulHews earned 300 total points
ID: 8166720
I guess I would introduce a random element into the speed of the various objects:

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

LVL 38

Expert Comment

ID: 8166735
Also unsure why you are processing with two separate timers.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
###### Suggested Courses
Course of the Month13 days, 5 hours left to enroll