Legacy GM How to assing hierarchical value to variables without repeting positions

M

MrTkila

Guest
Hi,

I'm having trouble making a position system in a race game.

What I was expecting is that if any of the four players, for example Player A, hits the lap detection zone first he will be in first place and if Player B hits the lap detection zone next and both have the same ammount of laps Player B will be second place and if Player C hits the detection zone and has the same ammount of laps as A and B, he will be third, so Player D if he has less or the same amount of laps will be fourth place.

I have this code, and the problem is that if Player A and Player B have the same amount of laps I will get two players in the same position (1st place, 2nd place, 3rd place, 4rd place).

Code:
car_pos = ds_list_create();
//Assing Positions taking laps as reference (laps are stored in global.lapsa for player a, global.lapsb for player b, etc)
ds_list_add(car_pos, global.lapsa);
ds_list_add(car_pos, global.lapsb);
ds_list_add(car_pos, global.lapsc);
ds_list_add(car_pos, global.lapsd);
ds_list_sort(car_pos, false);

//convert 0 to 3 position values to 1 to 4 (global.posa determines position for player a, global.lapsb for player b, etc)
global.posa = ds_list_find_index(car_pos,global.lapsa)+1;
global.posb = ds_list_find_index(car_pos,global.lapsb)+1;
global.posc = ds_list_find_index(car_pos,global.lapsc)+1;
global.posd = ds_list_find_index(car_pos,global.lapsd)+1;

ds_list_destroy(car_pos);

Hope I can get some help! Thank you.
 
B

Becon

Guest
For me, if I was on something as simple as an oval track I might break the track into 4 pieces or add 4 more "detection zones". The detection zones would probably be at the 4 corners of the track. I would use them to check track position; are they going left/right or up/down on the track atm?

C--------------------B
|..................... |
D---------|----------A

If the cars are going from Detection Zone A to DZ-B...what car is closest to B? That car is in the lead. What is the second closest? That car is in second place. On my chart the line connecting A and B would probably be a collision detection too. Let's call that specific line A.5 If the cars are on A.5...which one is closer to B? That would prevent some craziness if someone stopped say a pixel before B and other cars had already rounded that corner. He would be in last...but he would be closer to B. But my making it so it only checks if you are closer to B if you are driving on A.5, then anyone around the corner would no longer be included. Lets call the lines between B and C B.5, then C.5 etc. If you are driving on A.5...if there is a car already on B.5 that car is ahead. Only compare car checks with the Detection Zone that is associated with the grount section you are driving on. If all but 1 were driving on A.5 and that one had the same amount of laps as the others but was already on B.5 or farther it would be in the lead with no need to check because the ground it's on already tells you.
I hope this makes some sort of sense. I wrote it like 3 different times. And I'm tired.

Let me know if this helped in any way or if I just confused everyone. =o)~

Also forget about that grey line on my "track" Formatting issues. Pretend that's the pits or something not needed for the explanation.
 

samspade

Member
Alternatively, you could just the distance linearly but place them on the circle with mod, or track distance and location separately. For example, with lap_length being 100, at dist = 150, dist mod lap_length would equal 50.
 
Top