# Moving an Array of Cars.

I want to produce a game with Visual Basic.
What I want to do is produce two lanes of cars, and one lane of cars move one direction across the screen and another lane of cars move across the screen the other direction.

I understand the best way to do this is to use an array of objects.  Right now I got an array of images.  Can anyone help me and tell me how I can do this?

It doesn't matter how many cars are there in each lane...

Thanks!
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Place 2 picture boxes on a form.  Picture1 & Picture2.

Now, in picture1 drag a label.  copy it 5 times into picture1. (Yes - do create array)

In picture2 drag a new label. copy it 5 times into picture2. (Yes - do create array)

Now place a timer in your form.

Now you have Picture1, Picture2, Label1(0-5), Label2(0-5)

just paste the following code in your form for an example.

Option Explicit

Dim myFor%

With Me
.Height = 1200
.Caption = ""
.Width = 2000
End With

With Picture1
.Top = 0
.Left = 0
.Width = Me.Width
.Height = 360
End With

With Picture2
.Top = 360
.Left = 0
.Width = Me.Width
.Height = 360
End With

For myFor = 0 To 5
With Label1(myFor)
.Left = Picture1.Left + (100 * myFor)
.Top = 60
.Width = 75
.Caption = myFor
.Height = 240
End With
With Label2(myFor)
.Left = Picture2.Width - (100 * myFor)
.Top = 60
.Width = 75
.Caption = myFor
.Height = 240
End With
Next

Timer1.Interval = 500
Timer1.Enabled = True

End Sub

Private Sub timer1_timer()

For myFor = 0 To 5
Label2(myFor).Left = Label2(myFor).Left - (Rnd * 200)
If Label2(myFor).Left < 100 Then Label2(myFor).Left = Picture2.Width - 100
Label1(myFor).Left = Label1(myFor).Left + (Rnd * 200)
If Label1(myFor).Left > Picture1.Width - 100 Then Label1(myFor).Left = 0
Next

End Sub

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Did you need something else on this??? Maybe a different example???
0
Commented:
Hi ccminted,
This old question (QID 20553657) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

GPrentice00
EE Cleanup Volunteer
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.