?
Solved

Moving an Array of Cars.

Posted on 2003-03-17
4
Medium Priority
?
242 Views
Last Modified: 2010-05-03
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
Comment
Question by:ccminted
[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
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
JH0401 earned 200 total points
ID: 8153828
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
 
LVL 1

Expert Comment

by:JH0401
ID: 8155099
Did you need something else on this??? Maybe a different example???
0
 

Expert Comment

by:CleanupPing
ID: 8532185
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
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8956503
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 20 hours left to enroll

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