Train Simulator
Train Simulator
I'm actually working on a train simulator. The simulator uses 2D vector graphics and allows multiple zoom levels.
It's work in progress. There is no user interface. Don't expect too much. It's not more than a simple demo.
Screenshot of Version 0.30
You can download the actual source code and Windows exe-file from proog.de. Pleas click on the flags - proog.de supports google translation (Java-script required).
http://proog.de/joomla/index.php/projekte/62-trains
It's work in progress. There is no user interface. Don't expect too much. It's not more than a simple demo.
Screenshot of Version 0.30
You can download the actual source code and Windows exe-file from proog.de. Pleas click on the flags - proog.de supports google translation (Java-script required).
http://proog.de/joomla/index.php/projekte/62-trains
-
- Posts: 1009
- Joined: Oct 11, 2008 7:42
- Location: ABQ, NM
- Contact:
How are you managing the keeping the little trains on the little tracks?
What kind of container are you using to dictate where the tracks connect, and maintaining their position to always be on a track?
Or else, they fall off the tracks, then they crash, and grow exponentially larger orange pixels which represent fire.
~Kiyote!
What kind of container are you using to dictate where the tracks connect, and maintaining their position to always be on a track?
Or else, they fall off the tracks, then they crash, and grow exponentially larger orange pixels which represent fire.
~Kiyote!
Every train just stores it's position related to the track. The position of the train will be calculated from the track's position.kiyotewolf wrote:How are you managing the keeping the little trains on the little tracks?
What kind of container are you using to dictate where the tracks connect, and maintaining their position to always be on a track?
That would be pretty cool.kiyotewolf wrote:Or else, they fall off the tracks, then they crash, and grow exponentially larger orange pixels which represent fire.
When you run the program, you will find some tracks with an open end (number 9, 10 and 11).
Actually the trains just change the direction.
There is no collision detection at the moment. So you can drive different trains on the same track and let the trains drive over another.
Edit: correcting typos.
Last edited by oog on Jul 14, 2011 20:19, edited 1 time in total.
-
- Posts: 1009
- Joined: Oct 11, 2008 7:42
- Location: ABQ, NM
- Contact:
About drawing trains.
I use strings to define vector graphics items like trains and buildungs. The characters of the string stand for graphics commands and parameters.
There are some subroutines, that help building the string similar to graphics commands.
iAddColor(col) for example adds a color(col) command to the string.
There are also Zoom-Commands iAddZoomIn and iAddZoomOut. They are used to show more or less details in different zoom levels.
Example:
w.iBuild(i)= _
iVehicle _
+iAddZoomOut(200) _
+iAddColor(1) _
+iAddLine(-20,-70,20,70) _
+iAddLine(20,-70,-20,70) _
+iAddZoomIn(200) _
+...
Every vector item will be placed on the screen with two pair of coordinates (PointA and PointB).
A coordinate is a 8 bit value. PointA and PointB are located at (-100,0) and (+100,0) within a (-128,-128) - (127,127) grid. For a train, PointA and PointB represent the axis (wheels).
Test for yourself:
You can place a new item at the cursor position by pressing "n" (new item). A Building will appear under the mouse cursor.
Then click with the left mouse button to select the object (use a short click).
There will appear a yellow circle around PointA and a blue one around PointB.
Press + or - to change the item (other building, train, etc.).
Click into a point marker, hold down the mousebutton and drag it. PointA moves the item while PointB change size an direction.
Press "del" to remove the item, or click outside a Point marker to deselect the item.
The next program version will have a more stable drag function, actually you should not move the mouse too fast while dragging.
I use strings to define vector graphics items like trains and buildungs. The characters of the string stand for graphics commands and parameters.
There are some subroutines, that help building the string similar to graphics commands.
iAddColor(col) for example adds a color(col) command to the string.
There are also Zoom-Commands iAddZoomIn and iAddZoomOut. They are used to show more or less details in different zoom levels.
Example:
w.iBuild(i)= _
iVehicle _
+iAddZoomOut(200) _
+iAddColor(1) _
+iAddLine(-20,-70,20,70) _
+iAddLine(20,-70,-20,70) _
+iAddZoomIn(200) _
+...
Every vector item will be placed on the screen with two pair of coordinates (PointA and PointB).
A coordinate is a 8 bit value. PointA and PointB are located at (-100,0) and (+100,0) within a (-128,-128) - (127,127) grid. For a train, PointA and PointB represent the axis (wheels).
Test for yourself:
You can place a new item at the cursor position by pressing "n" (new item). A Building will appear under the mouse cursor.
Then click with the left mouse button to select the object (use a short click).
There will appear a yellow circle around PointA and a blue one around PointB.
Press + or - to change the item (other building, train, etc.).
Click into a point marker, hold down the mousebutton and drag it. PointA moves the item while PointB change size an direction.
Press "del" to remove the item, or click outside a Point marker to deselect the item.
The next program version will have a more stable drag function, actually you should not move the mouse too fast while dragging.
How to use your own bitmap.
For an example, take a screenshot of the FreeBASIC Forum logo and save as "data/fblogo.bmp".
Then edit the "data/trainini.txt" file like in the example.
After running the trainxxx.exe, press "m" to show the background map.
You will see the logo in the background.
Then you can build your own track. Example for a "horse track"
For an example, take a screenshot of the FreeBASIC Forum logo and save as "data/fblogo.bmp".
Then edit the "data/trainini.txt" file like in the example.
Code: Select all
groundcolor
0xd0d0c0
#
# load bitmap
#
loadbmp
1 # bmp 1
fblogo.bmp
#
# place map on screen
#
newmap
1 # place map 1
logo
1 # use bmp 1
1_000_000_000 # position x
1_000_000_000 # position y
10_000 # scale, 1 pixel = 10 m
10 # zoom min
200_000 # zoom max
You will see the logo in the background.
Then you can build your own track. Example for a "horse track"
-
- Posts: 289
- Joined: Oct 10, 2006 7:19