moving cars and logs in array.

Posted on 2003-03-18
Medium Priority
Last Modified: 2010-05-01
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?


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()


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
Question by:n-generation
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
  • Learn & ask questions
  • 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
LVL 38

Expert Comment

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

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question