Andy said:
You can do it, but I think it'd be dead hard to do anything beyond
trivial.
I agree that the program he is describing will not be simple, VB.Net is
perfectly capable of doing complex programs.
One road and one car would be kind of easy.
Say.
The car just goes left to right until it comes to the lights... then
reappears on the left of the picture.
The lights turn from red to amber to green....
The car stops if < so-many-pixels from the lights if they're red.
You can hard code all the tricky bits.
You need a car.jpg a background.jpg and three lights.jpg.
Or maybe one lights.jpg and you draw a green/red/amber bit on it.
More cars and more roads is hurting my head just thinking about it.
You're tallking the sort of programming that games designers do.
You need to think about collision detection between the cars.
The cars behavior should not depend at all on the visual representation
on the screen. The car, the traffic light, the road, and all the other
items in the game would be defined as classes with separate properties.
The display on the screen would simply reflect the current state of
all the objects. Look up the Model - View - Controller design pattern.
How do the cars "know" which road they're on and where it goes.
How do they work out that there are lights ahead.
I'd imagine the network of roadways would be modelled with some sort of
graph structure. The cars would not have to know what is ahead, they
would just check to see if there is a light at their current location
and what it's state is (red, yellow, or green). Pick up a college
textbook on data structures. There is a lot of computer science theory
on graphs, trees, etc. that would be useful.
The algorithm woukd be really tricky.
I'm not exactly sure how games designers do this.
I think there's like a mathematical model they use controls the movement and
where stuff is and hence collision detection.
This model is then used by the graphics bits.
The algorithm would certainly be challenging, but each object could be
written to be independent. The car for example would have properties
such as speed, direction, etc. When the simulation is started, the car
would operate pretty much independent of the other vehicles. If two
cars happened to enter the same location, that would constitue a
collision.
I'm not clear if the original poster is trying to create some sort of
game (like Sim City) or a traffic simulator to simulate the flow of
traffic.
Simulation is hard though.
I would imagine the vast majority of us on this ng do business
programming.
It's definitely an app that would require careful design, but VB.Net is
more than capable of handling it, IMHO.
Cheers,
Chris