First time posting on these forums so go easy on me!
I've been programming a race game which has been going quite well. I've just discovered now how hard it is to set up player positions!(As in 1st, 2nd, 3rd, etc). From research I've discovered that the easiest way of doing this is through checkpoints which I've successfully managed to set up. Each player races through the checkpoints in the game and this progress is stored as an int. There's 2 int, one for laps and one for checkpoints. When the checkpoint integer reaches a certain number it resets back to zero and the lap integer is incremented.
I was planning to compare these to work out player positions. Hopefully by putting them into arrays and then sorting them so it could tell me the player's positions in the race as the person with the high lap and checkpoint count would surely be the highest ranked.
Also to make the measuring of player positions more accurate I've measure the distance between checkpoints. At each checkpoint it works out how far the player is from the next point and using the distance from the previous to the next I'm able to generate a percentage which tells me how far the player is from the lap.
What I was hoping to do is create an integer worked out from the players race progress. So for example going through a checkpoint would increment the player's race progress integer by 100. If there were 12 checkpoint a complete lap would obviously be 1200. 2 laps would be 2400 and so on. By inverting the percentage I generated earlier it gives me the distance to the next checkpoint. so for example a player 75% towards the 4th checkpoint in their first lap would have an integer of 375, whereas a player 50% towards the first checkpoint in their second lap would have an integer of 1250.
I hope that logic made sense.
So what I'm essentially looking to create is a sort of table, using the player's object or even a unique player id as an index. And then to sort this table by the player position int.
I think this maybe possible through multidimensional arrays but I'm quite unsure. I've looked into associative arrays, dictionaries and hashtables but I'm still pretty unclear on what to do.
Would really appreciate being pointed in the right direction. Thanks!