Update hiscore.c
This commit is contained in:
+57
-9
@@ -16,14 +16,15 @@ SDL_Rect cursor_last = {128, 146, 7, 5}; // last cursor position
|
|||||||
SDL_Rect fnt = {128, 146, 7, 5}; // Name entry cursor
|
SDL_Rect fnt = {128, 146, 7, 5}; // Name entry cursor
|
||||||
char pen1 = 0xff;
|
char pen1 = 0xff;
|
||||||
|
|
||||||
int score = 65535; // current score
|
int score; // current score
|
||||||
char level_r = 0x1E; // game level (remaining)
|
char level_r = 0x1E; // game level (remaining)
|
||||||
char level_c = 0x00; // game level (current)
|
char level_c = 0x00; // game level (current)
|
||||||
int total = 0x00; // smashed tiles
|
int total = 0x00; // smashed tiles
|
||||||
|
int hscores1[8] = {1000, 780, 600, 500, 400, 300, 200, 100};
|
||||||
|
|
||||||
int hscores [8]; // high score panel - scores
|
char hscores[8][7+1] = {{"......."}, {"......."}, {"......."}, {"......."}, {"......."}, {"......."}, {"......."}, {"......."}}; // high score panel - scores
|
||||||
char names[8][7+1]; // high score panel - names
|
char names[8][7+1] = {{"HULK "}, {"EARTH "}, {"BUSH "}, {"AXE "}, {"PERFECT"}, {"POWERS "}, {"TUGBOAT"}, {"DINO "}}; // high score panel - names
|
||||||
char name_temp[7+1] = "ANTARES";
|
char name_temp[7+1] = " ";
|
||||||
|
|
||||||
///////////////// DISPLAY RESTART /////////////////
|
///////////////// DISPLAY RESTART /////////////////
|
||||||
int Ren_restart(void) {
|
int Ren_restart(void) {
|
||||||
@@ -36,6 +37,36 @@ int Ren_restart(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////// INSERT ENTRY INTO HIGH SCORE LIST ///////////////////////
|
||||||
|
int insert_score(int new) {
|
||||||
|
int hscores_new = new;
|
||||||
|
int counter;
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
if (hscores_new > hscores1[i]) {
|
||||||
|
counter = 8 - i; // find position in list to insert
|
||||||
|
for (int j = 0; j < counter; j++) {
|
||||||
|
hscores1[7 - j] = hscores1[6 - j]; // shift right from position to make space, drop off last position
|
||||||
|
for (int k = 0; k < 8; k++) {
|
||||||
|
names[7 - j][k] = names[6 - j][k]; // do same as above for name array
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hscores1[i] = hscores_new; // insert new high score into integer aray
|
||||||
|
for (int k = 0; k < 8; k++) {
|
||||||
|
names[i][k] = name_temp[k]; // insert new name into name ASCII array
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int j = 0; j < 8; j++){
|
||||||
|
its(hscores1[j], str); // convert high scores to ASCII code
|
||||||
|
for (int k = 0; k < 8; k++){
|
||||||
|
hscores[j][k] = str[k]; // store in high score ASCII array
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0; // all done
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////// RENDER NAME ////////////////////
|
/////////////////// RENDER NAME ////////////////////
|
||||||
int Ren_name(void){
|
int Ren_name(void){
|
||||||
SDL_SetRenderDrawColor(sr, 0xff , 0xff , 0xff, 0xff); // white pen
|
SDL_SetRenderDrawColor(sr, 0xff , 0xff , 0xff, 0xff); // white pen
|
||||||
@@ -95,22 +126,32 @@ int Ren_cursor(void) {
|
|||||||
|
|
||||||
///////////////// DISPLAY GAME OVER /////////////
|
///////////////// DISPLAY GAME OVER /////////////
|
||||||
int Ren_gameover(void) {
|
int Ren_gameover(void) {
|
||||||
|
int counter = 0;
|
||||||
|
cursor.x = 128;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
newh[i] = 0x20;
|
||||||
|
name_temp[i] = 0x20;
|
||||||
|
}
|
||||||
while (event.key.keysym.sym != SDLK_RETURN) {
|
while (event.key.keysym.sym != SDLK_RETURN) {
|
||||||
Ren_cursor();
|
Ren_cursor();
|
||||||
SDL_PollEvent (&event);
|
SDL_PollEvent (&event);
|
||||||
if (event.type == SDL_KEYDOWN) {
|
if (event.type == SDL_KEYDOWN) {
|
||||||
if ((event.key.keysym.sym >= SDLK_0 && event.key.keysym.sym <= SDLK_9) || (event.key.keysym.sym >= SDLK_a && event.key.keysym.sym <= SDLK_z) || (event.key.keysym.sym == SDLK_SPACE) || (event.key.keysym.sym == SDLK_RETURN)) {
|
if ((event.key.keysym.sym >= SDLK_0 && event.key.keysym.sym <= SDLK_9) || (event.key.keysym.sym >= SDLK_a && event.key.keysym.sym <= SDLK_z) || (event.key.keysym.sym == SDLK_SPACE) || (event.key.keysym.sym == SDLK_RETURN)) {
|
||||||
printf("event.key.keysym.sym: %02x\n", event.key.keysym.sym);
|
// printf("event.key.keysym.sym: %02x\n", event.key.keysym.sym);
|
||||||
|
name_temp[counter] = event.key.keysym.sym; // ascii name array
|
||||||
newh[(cursor.x - 128) / 8] = event.key.keysym.sym; // fill name array
|
newh[(cursor.x - 128) / 8] = event.key.keysym.sym; // fill name array
|
||||||
SDL_RenderPresent(sr);
|
// SDL_RenderPresent(sr);
|
||||||
|
counter++;
|
||||||
|
if (counter > 7){counter = 7;}
|
||||||
cursor.x = cursor.x + 8; // advance cursor
|
cursor.x = cursor.x + 8; // advance cursor
|
||||||
if (cursor.x == 192) {
|
if (cursor.x == 192) {
|
||||||
cursor.x = 184; // 192 - 8
|
cursor.x = 184; // 192 - 8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (event.key.keysym.sym == SDLK_BACKSPACE)
|
else if (event.key.keysym.sym == SDLK_BACKSPACE) {
|
||||||
{
|
name_temp[counter]=0x20; // ascii name array
|
||||||
|
counter--;
|
||||||
|
if (counter < 0){counter = 0;}
|
||||||
cursor.x = cursor.x - 8; // backspace
|
cursor.x = cursor.x - 8; // backspace
|
||||||
if (cursor.x == 120) {
|
if (cursor.x == 120) {
|
||||||
cursor.x = 128; // 120 + 8
|
cursor.x = 128; // 120 + 8
|
||||||
@@ -124,10 +165,17 @@ else if (event.key.keysym.sym == SDLK_BACKSPACE)
|
|||||||
|
|
||||||
////////////////// HANDLE END GAME /////////////////////////
|
////////////////// HANDLE END GAME /////////////////////////
|
||||||
int end_game(void) {
|
int end_game(void) {
|
||||||
|
// score = 801;
|
||||||
|
|
||||||
if (game_end == 1) { // restart
|
if (game_end == 1) { // restart
|
||||||
Ren_restart(); // Ren_restart();
|
Ren_restart(); // Ren_restart();
|
||||||
} else if (game_end == 2) { // game over
|
} else if (game_end == 2) { // game over
|
||||||
|
if (score < hscores1[7]) {
|
||||||
|
Ren_restart(); // if score less then lowest on list, no name entry
|
||||||
|
} else {
|
||||||
Ren_gameover();
|
Ren_gameover();
|
||||||
|
insert_score(score); // else display name entry dialog
|
||||||
|
}
|
||||||
}
|
}
|
||||||
check_key();
|
check_key();
|
||||||
reset();
|
reset();
|
||||||
|
|||||||
Reference in New Issue
Block a user