I'm happy to say that I was able to complete the solution to display the score system in my game. Please let me know what you think.
Here is what I did:
I created sprites for each number. For example:
ts_sprite zero = { offscreen, offscreen, 3, 5, 0, zeroBitmapFont };
There is a bitmap for each number.
Then I defined 4 sprites, one for each digit (for a number from 0 to 9999), displayed on the top right:
ts_sprite onesdigit = { 91, 2, 3, 5, 0, zeroBitmapFont };
ts_sprite tensdigit = { 87, 2, 3, 5, 0, empty };
ts_sprite hundredsdigit = { 83, 2, 3, 5, 0, empty };
ts_sprite thousandsdigit = { 79, 2, 3, 5, 0, empty };
(the empty sprite contains the same size of a number, but with ALPHA on each pixel)
I defined a score global variable:
int score = 0;
And two arrays: One for all the numbers, and one for all the digits:
ts_sprite * numbersBitmapFont[10] = { &zero, &one, &two, &three, &four, &five, &six, &seven, &eight, &nine };
ts_sprite * digits[4] = { &thousandsdigit, &hundredsdigit, &tensdigit, &onesdigit };
I added a scoreUpdate() function to the loop(), and every time I kill an enemy I add +1 to the score variable.
Here is what's in scoreUpdate():
void scoreUpdate() {
//Convert score to string
String scoreDisplay = String(score);
//Determine how big is the score and how many digits will be needed to display it
int startAt = 4 - scoreDisplay.length();
//Go through the string, and draw each character
for (int i = 0; i < scoreDisplay.length() ; i++) {
int c = scoreDisplay.charAt(i);
//c will have the ASCII value of the character, number 0 is 48 in ASCII
int n = c - 48;
//make digit be the right number
digits[startAt+i]->bitmap = numbersBitmapFont[n]->bitmap;
}
}
Cheers,