Online Highscores and Bonus Points

April 10, 2011

Bad news: Asteroids is not yet finished.

Good news: Asteroids will have lots of cool stuff in the final version!

Since my call for levels in my previous post I received a lot of uber awesome levels. I was really blasted away by the creativity of some contributions and it is very impressive to see what one can get out of such simple mechanics. It was very hard to order the levels into increasing difficulty while simultaneously trying keep the gameplay fresh and interesting. But you will get to see it soon enough…

Other than playing and sorting levels, I worked on two new features that I thought would be very interesting.

Online Highscore

When using the online highscore, the scores get submitted to the server and the top 10 scores from the server will me displayed in-game. This is all done by using SDL_net and performing some hand crafted HTTP queries to a small PHP script on the server. The PHP script itself stores the  highscore in a SQLite database which was super easy to set up.

As everything is transmitted in clear text I also added some protection to ensure only valid submissions are added to the database. I am using a shared secret for the PHP script and the game which gets appended to the submission values (name + score) and then hashed. As a hashing function I use Aaron D. Gifford’s sha256 code which should be sufficiently safe for this. What I really like about it is, that I could publish the code for both the script and the game but this would still be not enough to spam the highscore unless someone succeeds to extract the shared secret – Nice!

In the game options menu one can choose whether one wants to use this online highscore mode or only use the local highscore. The following screen shot should be pretty self explanatory:

Whether the online mode is being used or not can be seen by the highlighted “-online-” at the top of the highscore screen. In “-offline-” mode it uses the values stored in the game data path.

Bonus Points

Also there will be bonus points given when one finishes a level fast. For this I needed a time to compare to. Inspired by the PAR time in DOOM I played through all levels and added a few seconds. I am using a quadratic function to compute the amount of bonus points, depending on time and the number of asteroids in the level. Only when the level was finished before the PAR time. Currently I am tweaking the parameters of the function to properly reward the speeders.

I decided to give points at the end of the level so that one cannot achieve higher scores by playing a level with many asteroids multiple times by committing suicide on the last remaining asteroid and therefore getting twice as many points on the level.

Some Polishing

To make the level switching a little nicer, I am now displaying some informations about the level, such as the number, title, and the author of the current level:

Furthermore I worked on the credits screen and made new sounds by using sfxr (which is super awesome!). But I’ll write about all that another time…