Message Board


Message Board > Fenix / Bennu / Gemix / DIV > Best Way To Do A First, Second, Third Etc Counter In Fenix?

December 8, 2006, 21:56
Goity
Look at me, I'm unique!
6 posts

I want to know what the best way to do this for a racerwould be? I can't think of how I would do it.
____________
#
December 8, 2006, 22:23
Rincewind
programmer
1545 posts

What exactly do you mean? Are you talking about iteration counters used in loops, or ....?
____________
Personal website: http://www.loijson.com
#
December 8, 2006, 22:39
Goity
Look at me, I'm unique!
6 posts

like in a racer, how it is calculated who is first, second etc.
____________
#
December 8, 2006, 23:36
Eckolin
Quite Whiskered
388 posts

You could divide the track into sections and sort the racers by the section number and lap number.
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
December 8, 2006, 23:38
Goity
Look at me, I'm unique!
6 posts

maybe, but it would be a little inaccurate
____________
#
December 8, 2006, 23:45
Rincewind
programmer
1545 posts

To time the racers you can use Fenix' timers. You can set a timer like:

timer[0]=0;

From that point the timer will start counting time. So set a timer to 0 for each car on the start of the race, and then check and store the timer's value for each car on the point of finish.

Then you need to sort all the times to determine the places.
____________
Personal website: http://www.loijson.com
#
December 9, 2006, 00:20
Rincewind
programmer
1545 posts

Variables declared:

Code:
Amount_of_cars = 3;

Struct Race_car[2];
      Lap_time; 
End

Amount_of_positions =3;
Position[3]; //element 0 is not used

i;j;k;

'

Let's assume that Lap_time has been filled out for every Race_car element, using timers. Also let's assume all positions have been set to zero.

Now let's fill our Position list with the appropiate car numbers:

Code:
For (i=0; i<Amount_of_cars; i++)
      For (j=1; j<=Amount_of_positions; j++)
            If (Race_car[i].Lap_time <Race_car[Position[j]].Lap_time)
                  For (k=(j+1); k<=Amount_of_positions; k++)
                        Position[k]=Position[k-1]; //All cars under the changed position move down one position in the position list.
                  End
                  Position[j] = i; //Sets the postition to the car that was being checked
            End   
      End      
end

'

Please ask if there's anything you don't understand.
____________
Personal website: http://www.loijson.com
#
December 9, 2006, 15:39
Frimkron
Frustrated Megalomaniac
703 posts

I dont think you understand the problem, Rincewind.

My suggestion would be the same as Eckos. The level of accuraccy just depends on how many sections you're willing to divide the map into.

Or, actually, here's another idea. You could define a path around the race track as a set of lines, then for each car, find the line they are nearest to and the point along that line they are nearest to. From this you could then calculate how far around the track they are and it would be more accurate, in terms of being able to pick out a 1st 2nd 3rd and 4th anyway.
____________
#
December 9, 2006, 16:22
Rincewind
programmer
1545 posts

Quote:
I dont think you understand the problem, Rincewind.


So then Frimkron, would you be so kind to explain to me what you think Goity means?
____________
Personal website: http://www.loijson.com
#
December 9, 2006, 17:53
PEader
お前はもう死んでいる
1486 posts

I always wonder how this is done. Somebody should do an article/tutorial on it.
____________
I see 57,005 people.
#
December 9, 2006, 20:01
Eckolin
Quite Whiskered
388 posts

Quoting Frimkron:
I dont think you understand the problem, Rincewind.

My suggestion would be the same as Eckos. The level of accuraccy just depends on how many sections you're willing to divide the map into.

Or, actually, here's another idea. You could define a path around the race track as a set of lines, then for each car, find the line they are nearest to and the point along that line they are nearest to. From this you could then calculate how far around the track they are and it would be more accurate, in terms of being able to pick out a 1st 2nd 3rd and 4th anyway.


That's actually the same idea and the implementation I would've chosen. Defining the path around the track as a set of lines and points then picking the closest point effectively divides the tracks into voronoi-like regions.

Edit: It's a neat explanation on how it would work exactly nonetheless.

[Edited on December 9, 2006 by Eckolin]
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
December 9, 2006, 20:04
Frimkron
Frustrated Megalomaniac
703 posts

I see what you mean, Ecko, but using a path rather than regions would mean you can actually calculate how far the car is along the line - essentially giving you an infinite number of positions around the track.
____________
#
December 9, 2006, 20:05
Eckolin
Quite Whiskered
388 posts

Granted.
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
December 9, 2006, 20:29
Frimkron
Frustrated Megalomaniac
703 posts

Ecko and I had another idea while discussing this over msn. What you could do is place a special point on the inside of each bend, then how far you've progressed around that bend can be determined by the angle from the point to the car. For a simple circular track, for example, you just need one point int the centre. For an S bend, you would put a point on the inside of each curve along the S. Then you could split the track into regions to determine which point to measure from on each bend.
____________
#
December 11, 2006, 14:33
Dennis
どこかにいる
2092 posts

I would agree with the line trick.



In my example the dots are players. let's say the pink player is on his 2nd lap the rest is still on their first lap. I tried to make every straight line a different color where they meet/curve. Every line has a number. The first blue line pointing to the up left is line number 1. So the red one is nr 2 and the green nr 3 etc. the last one is number 11. Where the track gets complicated you get more lines.

Now you must calculate the position of the player tot left or right of the line. For each line have a control point at the start of the line. Now you try to calculate the distance to the car in the parallel direction of the line. This distance must be positive to find which line it belongs to. If more lines apply use the one in shortest distance. using this method the players get these line numbers:
each line is 1 as length and we calculate a floating point as percentage of how far the progress for that line is:

(line number + percentage on line) + ([lap_nr-1] * total_lines)

pink: 2.53289 + 11 = 13.53289
light blue: 2.12639 + 0 = 2.12639
green: 3.12544 + 0 = 3.12544
purple: 6.5812 + 0 = 6.58120
red: 7.2103 + 0 = 7.21031

so in my example:

1st: pink (13.53289)
2nd: red (7.21031)
3rd: purple (6.58120)
4th: green (3.12544)
5th: light blue (2.12639)


It might perhaps be difficult to calculate the position from the line, but maybe you get the point. It is not a simple task indeed.

[Edited on December 11, 2006 by Dennis]
____________
Kwakkel
#
December 12, 2006, 00:02
g105b
None
86 posts
lines & sections :)

I say have a hardness map where, for example, black is the track, red is walls, etc. but have shades of green as the different sections around the track (at each corner). Then the computer will know when you are in the next section, and can have blue points or control points on the image which also represent the corners. you can get_dist to the next control point, and the one who is closest to the control point furthest around the track is in 1st :)
____________
.g105b''
#
December 12, 2006, 11:12
Dennis
どこかにいる
2092 posts

Yeah, but g105b, place blue points in the corners:


____________
Kwakkel
#
December 12, 2006, 13:17
Sandman
F3n!x0r
1194 posts

The center of that circle will do the trick, no?
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
December 12, 2006, 13:24
Dennis
どこかにいる
2092 posts

then there is no need for get_dist sine it will be 0 always?
____________
Kwakkel
#
December 12, 2006, 13:30
Sandman
F3n!x0r
1194 posts

You can use the angle to calculate the positions, there is no need for multiple control points I'd say.
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
December 12, 2006, 15:26
Dennis
どこかにいる
2092 posts

How would you guys solve this?




it overlaps. I remember while playing mario kart that sometimes my position changed from 1st to 8th back to first when I jumped over it! :p

[Edited on December 12, 2006 by Dennis]
____________
Kwakkel
#
December 12, 2006, 22:28
DTM
Earthling!
821 posts

If the track is a continuous line then the next point/sector is either the one before or after the current. Not an overlapping one several sectors ahead.
____________
:o
#
December 13, 2006, 10:26
Dennis
どこかにいる
2092 posts

You can work with layers for an overlapping track
____________
Kwakkel
#
January 10, 2007, 12:24
g105b
None
86 posts
The idea of having different shades of green on a hardness map will still work.

Say each green colour had a different numerical value, starting at 0 and going through to 100.

The start/finish line will be 0, and the computer waits until the car is on 1, and then on 2, and then on 3....... when you go under the bridge, your colour number might be, say, 30. Then as you go over the bridge, your colour number might be 40. There will be no confusion at all - the computer should only ever look for the next number, the fact that you are on another part of the track should make no differece.
____________
.g105b''
#

Message Board > Fenix / Bennu / Gemix / DIV > Best Way To Do A First, Second, Third Etc Counter In Fenix?

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!