I am developing a game where I need to sort the score based on both how many coins the player collected and how long did it take. Higher number of coins and lower time taken are better. Also number of coins has higher precedence than time.
For example, suppose player A scored 7 coins in 15.26 seconds, player B scored 5 coins in 9.73 seconds and player C scored 7 coins in 13.87 seconds. Then the leaderboard scores should be like this:
- player C: 7 coins in 13.87 seconds
- player A: 7 coins in 15.26 seconds
- player B: 5 coins in 9.73 seconds
How to achieve this? My personal solution is this:
- Multiply number of coins by a large number (>= 100,000) to get X
- Multiply time value by 100 to convert it to an integer Y
- Then calculate final score = X - Y
Is this the correct way to do this?