Sunday 22 January 2012

What's the score?

I'm still undecided about whether to make the Zommers! "game" a score-based thing, or a "how long can you survive" type affair, so I thought I'd check out both scenarios.

This blog update is about the scoring system, or rather, how it works. Basically, you get 1 point for every Zommer killed, that much is obvious. What isn't obvious is how to display that score in game. Yes, I could just use the standard text output and reposition it somewhere on the screen, but that would be too easy, and look a bit pants, so I've gone for a sexy Orange font for the moment, and here's how it looks "in-game"...


...now that might not look too fancy, but compared to normal text believe me it is. And because it's made of sprites, changing the look and feel of it is simply a case of changing the graphic from which it's built. And here is that graphic...


...so if I wanted the score presented in a "space age" style font, I'd just edit that graphic and wouldn't have to change anything within the game code :)

So this block of code grabs that image, cuts it up into 10 equally sized pieces, and creates an animated sprite 10 frames in length, with 1 digit to each frame. It's repeated 4 times, once for each digit in the score readout...


...the "screen_w" variable you see there is just something I'm using to hold the value of the width of the screen. That's so this thing will work on PC's that are using a different screen resolution to the one I wrote this code on. As it happens, in this instance I'm using it to position the sprites which display the score.

So after doing that, it's just a case of looking at the current score variable, breaking it down into individual digits, then changing the displayed frame of the corresponding sprite to whatever is held by the score variable. I call this routine once every program cycle (which is 60 times per second), and as it's impossible to kill 60 Zommers in a single second, there is no chance of the displayed score lagging behind the actual score. 

At the moment the Zommers still don't cause damage to the player when they touch it, so once I have this scoring system exactly as I want it (or a timer system - I'm still undecided), creating a player damage routine is my next task.