So now that we have the ability to add and view player names, we would we like to add a leader board. We think this would really add a fun element to the game.
We’re going to start off simple. This first version will just show the current number of kills for the leading 10 players playing the game.
A player gets awarded one kill each time one of their weapons destroys another ship. When a player dies their kill total is reset to zero.
We are not attempting to save any information to disk at this time. For example, this does not include the ability to see how a player is doing over time. That would require us to implement the idea of player accounts so that the stats could be saved to disk.
Here is what I think the basic steps are going to be:
As of right now, when a player fires their laser (missile, plasma bolt, whatever it is), the game does not keep track of who fired it. It just gets created and flies off into space. But if we are going to start keeping track of kills, we need to understand who shot each missile. If that missile ends up blowing up another ship that we credit a kill to whoever fired it.
I think the way to do this is actually pretty straight forward: assign an ownerId to each missile. Then, if the missile blows something up we will be able to determine who should get credit.
I’ll need tp update:
- The Missile class with the new attribute
- The packing and unpacking code to include the new attribute
When a missile collides with a ship AND destroys it, we need to update the collision algorithm to award a a kill to the player who the missile was assigned to.
The player object will need to be updated to include the new kills attribute. I think this array of players is already sent down to the clients via the normal update cycle. If not I will have to include it.
When I’m in there I should look at the code and determine if the player array really needs to go down as frequently as the game objects. It probably doesn’t make sense to update the score 20 times a second. Once a second is probably more than enough. Need to save bandwidth anyway possible!
I’ll need a new control to display as a part of the HUD. This new leaderboard control will show the top ten players and their number of kills. This list should be sorted by number of kills in descending order.