Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

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!
0
ccminted
Asked:
ccminted
  • 2
1 Solution
 
JH0401Commented:
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%

Private Sub form_load()

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
 
JH0401Commented:
Did you need something else on this??? Maybe a different example???
0
 
CleanupPingCommented:
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
 
GPrentice00Commented:
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:

-->Accept JH0401's comments as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GPrentice00
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now