I’m trying to create a ranking system for a racing game, I have an array of AI cars and a separate variable for the players car. They are stored using ‘Car’ class which keeps track of the individual cars lap count and waypoint count (integers) - it also holds the car ID so I know which car is which.
I then combine all the cars (AI and Player) into one array called ‘racePositions’, I now want to sort that array first by the lap count (highest to lowest) and then look at the waypoint count to see which car is ahead of the other if they’re on the same lap count.
E.g. The unsorted version of ‘racePositions’ might look like:
[0] car: 1, currLap = 4, currWaypoint = 12
[1] car: 2, currLap = 4, currWaypoint = 2
[2] car: 3, currLap = 2, currWaypoint = 12
[3] car: 4, currLap = 6, currWaypoint = 5
But the sorted array would look like:
[0] car: 4, currLap = 6, currWaypoint = 5
[1] car: 1, currLap = 4, currWaypoint = 12
[2] car: 2, currLap = 4, currWaypoint = 2
[3] car: 3, currLap = 2, currWaypoint = 12
I’m not sure how to do the sort and I’ve been looking at it for so long I think I’ve got the coders version of writers block. I feel like the answer is staring me in the face but I just can’t see it haha, any help would be much appreciated
Thanks