train signal box simulation advice

hiya all, just singed up to this place :stuck_out_tongue:

I’m developing a train simulation game of a small train network,
It will be from a birds eye view, and the main aim features will be to stop and start the train with the signals, as if you worked in the signal box, and also using the normal signal box controls, be able to shunt a train from one track to another,

now,

  1. I’m just wondering I need a good data structure to store each of the few trains (and the various different types of carriages and carts the pull), any ideas on what data structure I use

  2. any ideas on whether i could map the track to a 2d array, that i could then show on screen mapping it to a grid? or would their be a better way in your opinion to display the simulation (tracks and train) on the screen from a birds-eye-view

  3. anyone know of any java train simulations/games, that have been made before that i could have a look at the code, to see in which way other people have gone??

thanks any help is very much appreciated indeed

  1. Just make your own extension of Object, perhaps a “Car” class. This would contain variables for x/y position, width/height, etc. All of the global ones. Then make its subclasses: FreightCar which could have carrying capacity and stores an Object inside it, Locomotive which would have a speed and would be required to drag other carts, etc. If you were really ambitious you could have real physics, giving every cart a mass, the track friction, and then moving everything using the locomotive’s force.

  2. Yes, a grid sounds like it is probably the best solution. I envision something like the Brio train sets, where you gave certain pieces you can place to do what you want, like a curved track, and straight track, etc. But if you wanted real robustness you could have Pen tool that let you draw the track (a series of lines), then have the train move with the slope of the line it is currently connected to.

It all depends on how much time you want to spend, but a grid seems like the easiest solution.