indielib.com

IndieLib Forum
It is currently Sat Dec 15, 2018 6:42 am

All times are UTC




Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Fri Mar 13, 2009 8:43 pm 
Offline

Joined: Tue Feb 10, 2009 7:52 pm
Posts: 33
Entering the competition.
My favorite toy I never had always was an electric model railway. Little trains that run on little tracks. The speed was controlled by a transformer (controling the amount of electic power the trains get). At least that is the way I remember it.

Should be quite simple to display from above. So I'll give it a try. Lay out some tracks and let a little electric train run on it and let the user control the speed of the thing.

Yet not sure, how to turn this into a game. Should there be multiple trains and user has to switch some tracks to prevent collisions? Or are there stations where the train has to pick up some goods and deliver it someplace else?

So little time, only 4 weeks to finish something. So I better start with the basics and see, how much time is left then. So I guess I'll start with some painting today.


Last edited by Andi on Sun Apr 12, 2009 8:27 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 13, 2009 9:10 pm 
Offline
User avatar

Joined: Tue Mar 10, 2009 5:18 am
Posts: 109
Location: In the fourth dimension
Great idea! More toy-like and simple than mine I admit. :p


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 14, 2009 12:45 pm 
Offline
User avatar

Joined: Sat Dec 20, 2008 8:46 pm
Posts: 137
Location: Sweden
If you need ideas for gameplay, check out OpenTTD.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 15, 2009 7:44 pm 
Offline

Joined: Tue Feb 10, 2009 7:52 pm
Posts: 33
Wow, OpenTTD looks awesome! I am sure they implemented tons of great ideas. I played the Sid Meyer original way back and was impressed with all the gameplay. Thanks, Metadon, for the link.

I'm still not done to lay down the basics. Still not sure, how to do the train movement technically. Currently I am thinking, the train should just follow a certain line of pixels, so that I could paint a map without worrying about certain blocks or some numbering. Just free painting. But still, my first draft still looks very block like to me. :) Old habits I guess.

Image


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 15, 2009 8:11 pm 
Offline
User avatar

Joined: Sat Dec 20, 2008 8:46 pm
Posts: 137
Location: Sweden
Firstly, I'm not sure what you mean with "painting" a map. If you mean that you will draw a map in ms paint or similar then i think it might be a little difficult. More difficult than laying down tracks in the game, anyway :P

I'm probably biased here, but I think using my vector2 class will simplify things. Let me explain. If you have a track going from point A to point B, and all track segments are of lenght 10, for simplicitys sake, all you would have to do is tell the train what part of track it is on, use the linear interpolation between two points and voila, moving train.

In psuedocode:
Code:
Track[1].Start = Vector2(0,0);
Track[1].End = Vector2(0,10);
Train.Pos = Vector2(0,0);
Train.Track = 1;
Train.TrackPos = 0;
Train.Speed = 0.1; (Translates to 1 px, 0.1*10)

//In game loop
Train.TrackPos += Train.Speed*delta;
Train.Pos = Track[Train.Track].Start.Lerp(Track[Train.Track].End, Train.TrackPos);


This would move the train along Track[1] with a speed of 1px per second. Adding more tracks is just a matter of setting up track connections and checking if Train.TrackPos > 1 in which case move to next track segment (and set TrackPos to 0) or if its < 0 in which case move to previous track segment (and set TrackPos to 1).

Wow, that went on a bit longer than I had expected, probably due to my love of trains :P. Hopefully it will be of some help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 6:27 pm 
Offline

Joined: Tue Feb 10, 2009 7:52 pm
Posts: 33
Thanks Metadon for the hint to use vectors. Seems like a fast way to set up a track programmatically. But as far as I understand, the track segments (vectors) would describe straight lines. No curves.

I'm not sure how it would look but I presume that a train should go around smooth curves instead of abrupt corners. Reminds me of splines or what they call it. But I guess that would be overkill here.

But I looked at the code of vector2 and at least could use the distance function and the angle-functions to determine collision and the direction of a train.

I imagine that the wagon object will know three pixels. One at each end and one in the middle. The middle one determines the position. The two pixels at each end are used to determine the rotation of the gfx (using two vector2 objects). And these three pixels move synchronously along the track as the train moves. I hope this works. Still have to test this.

Yet I only managed to set up a project and start reading the painted image, converting it to track-data. Really wish I had more time per day :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 6:50 pm 
Offline
User avatar

Joined: Sat Dec 20, 2008 8:46 pm
Posts: 137
Location: Sweden
Yes, those track segments I described would be straight. Many segments in a row, each one a bit more angled, could however be described as atleast a psuedocurve.

Theoretically you could do perfectly curved tracks with my proposed method, if only by using 1px track segments. It is doable. However, using 10px tracks should be able to give an approximate illusion of curves while still being technically feasible.

If this isn't enough you could shorten each individual track segment to 5px or so and use a curve function to place them in the best allowed positions to fit the curve. You would not get a perfect curve, but to the end user there wouldn't be much difference.

One thing you should be aware of, the function that gives the angle between two vectors gives you the angle from -180 to 180. To give you the angle from 0 to 360 use this function to convert it:
Code:
int angleToReal(float angle)
{
   if(angle < 0) angle = 360 + ((int)(angle)%360);
   return (int)(angle)%360;
}


You only really have to use one point for the wagons, as you get the angle from the start- and endpoint of the track segment it is on.

Good luck, I hope to see some trains moving along soon! :D


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 22, 2009 1:14 pm 
Offline
Site Admin
User avatar

Joined: Wed Dec 26, 2007 1:38 am
Posts: 626
Location: Murcia, Spain
When I was a child, trais were something I always askef in christmas. If you are able to put a little bit of that magic in your game, this is going to be great.

Keep the good work.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 22, 2009 9:17 pm 
Offline

Joined: Tue Feb 10, 2009 7:52 pm
Posts: 33
Status update: over a week now and still fighting with the right data structure. One train sprite is already driving along the tracks. Train is fast, I'm too slow!!!

1 pixel movement per frame is more than enough for the top speed, so at least there is no need to do more than 1 pixel in one step.

Now all that's left to do for a first demo:
- better data structure for switches (is this the right english term for those points where the train can choose between two different ways to go?)
- finish first draft of background picture with shaped tracks and two frame animated switches
- train needs to calculate his rotation angle
- train needs to tow some wagons after him

Hope to get this done the coming week. On the weekend just could not find any time for this. Too many kids demanding too much attention :) So the time really starts to get short on me.

This is a section of the first really drawn tracks and a first train. Still not sure about the colors (as always).

Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 25, 2009 8:20 pm 
Offline

Joined: Tue Feb 10, 2009 7:52 pm
Posts: 33
Status update:
Now, finally, I think I have the data for the trains sorted out.
Phew, never thought of this being so hard for me. Seems my brain is way smaller than I thought :)
I am using a Ring-Array for each train where the last n coords are saved continuously and each wagon in the train just gets an offset into this array. This seems to work fine now. Today I saw the first 5 trains, each with multiple wagons, all roll their way through the one and only level. Hurray!

Can't upload a screenshot right now, because I'm at work. More to see at the weekend.

Next steps in the plan:
- improve graphics
- make three real levels
- give each train its own graphics and color

Hope to get a demo with these features done soon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 27, 2009 9:48 pm 
Offline

Joined: Tue Feb 10, 2009 7:52 pm
Posts: 33
The first demo is finished!

Demo 0.1 available for download: http://www.clevedon.de/TrainTraining-Demo0.1.rar

Screenshot:
Image

A few colorful trains run around randomly. No collision detection, no speed variations, just a first study to watch the movement of the wagons.

Now I really start to wonder, what game is that supposed to be? What do the trains have to do? What is the goal? How should the user control them? What is the meaning of life?

I guess this is the fun part. Coming up with some ideas. No real work :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 27, 2009 10:26 pm 
Offline
User avatar

Joined: Wed Jan 21, 2009 4:36 pm
Posts: 209
Location: San Diego, CA
This is awesome! When the contest is over I hope you will reveal your source code. I'd love to see the path following stuff.

Great work!

I'm watching this one! :wink:

Steve


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 27, 2009 10:31 pm 
Offline
User avatar

Joined: Tue Mar 10, 2009 5:18 am
Posts: 109
Location: In the fourth dimension
Maybe it should be a race. You have a limit of options for the tracks and you have to build a track that either connects to the other side, makes it to the other side faster, or both?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 28, 2009 4:57 pm 
Offline
User avatar

Joined: Sat Dec 20, 2008 8:46 pm
Posts: 137
Location: Sweden
Very nice :) Keep up the good work!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 28, 2009 8:48 pm 
Offline

Joined: Tue Feb 10, 2009 7:52 pm
Posts: 33
Thanks for the comments!

Today I got two ideas, two directions where to go with this.

First I thought, there should be stations, where the trains pick up some goods and deliver it to other stations. Each good has a certain color and train has to have a wagon in the same color, to transport it. There are source-stations (where goods are picked up) and destination-stations (where goods are dropped). The player has to 'program' the way of the train (set all switches to a certain position for that train only). Level is finished when all goods are delivered. No train collisions allowed. Two colliding trains stop and the bigger one pushes the smaller one away. Or something like that.

"Too complicated", my wife said. Player has to switch the switches in real time to prevent accidents. She may be right in keeping it simple. Player switches so that trains don't collide. If an accident happens, the level is over and player gets points for each second he survived. Plus the player can control game speed. Slow down all things (all trains) or speed them up. The faster he runs things the more points he gets for a second.

Not sure yet, which is the better idea. May be I should sleep over it and wait for tomorrow to have two more ideas, then get confused and with the time limit of the competition eventually go insane. Yeah, that sounds like a plan :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group