X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=score.c;h=b21345c6ef6152687a59d330d1d18f48e5778033;hp=77e8ab35ba8bb503343345da4a355405adf2cfef;hb=7f40ee1193e47c59f7297d9361314c731832f7b8;hpb=45925ff114a17b9c1c0a720ff668e2cb795cd761 diff --git a/score.c b/score.c index 77e8ab3..b21345c 100644 --- a/score.c +++ b/score.c @@ -22,7 +22,7 @@ #include #include -#include "SFont.h" +#include "font.h" #include "common.h" #include "config.h" @@ -31,32 +31,48 @@ #include "score.h" // High score table -struct highscore g_scores[N_SCORES] = { - {1*60*1000,"-"}, - {45*1000,"-"}, - {30*1000,"-"}, - {20*1000,"-"}, - {10*1000,"-"}, - {7*1000,"-"}, - {5*1000,"-"}, - {3*1000,"-"} +struct highscore g_scores[2][N_SCORES] = { + { + {1*60*1000,"-"}, + {45*1000,"-"}, + {30*1000,"-"}, + {20*1000,"-"}, + {10*1000,"-"}, + {7*1000,"-"}, + {5*1000,"-"}, + {3*1000,"-"} + }, + { + {1*60*1000,"-"}, + {45*1000,"-"}, + {30*1000,"-"}, + {20*1000,"-"}, + {10*1000,"-"}, + {7*1000,"-"}, + {5*1000,"-"}, + {3*1000,"-"} + } }; -extern SFont_Font *g_font; +static char *titles[2] = { "Normal\n", "Easy\n" }; +int g_easy = 0; int cur_score = -1; // which score we're currently entering. void read_high_score_table() { FILE *f; - int i; + int i, j; f = open_score_file("r"); if(f) { // If the file exists, read from it - for(i = 0; i g_scores[i].score) return i; + if(score > g_scores[g_easy][i].score) return i; } return -1; } @@ -92,20 +111,26 @@ score_rank(int score) int new_high_score(int score) { - int i; - cur_score = -1; // assume not a new high score - if(score <= g_scores[LOW_SCORE].score) return false; + if(score <= g_scores[g_easy][LOW_SCORE].score) return false; read_high_score_table(); cur_score = score_rank(score); - if(cur_score < 0) return false; + return cur_score >= 0; +} + +int +insert_score(int score) +{ + int i; // Move all lower scores down a notch, losing lowest score forever. - for(i=LOW_SCORE; i>cur_score; i--) g_scores[i] = g_scores[i-1]; + if(strcmp(g_scores[g_easy][cur_score].name, "-") != 0) + for(i=LOW_SCORE; i>cur_score; i--) + g_scores[g_easy][i] = g_scores[g_easy][i-1]; // initialize new score entry. - g_scores[cur_score].score = score; - for(i=0; i<32; i++) g_scores[cur_score].name[i] = 0; + g_scores[g_easy][cur_score].score = score; + for(i=0; i<32; i++) g_scores[g_easy][cur_score].name[i] = 0; return true; } @@ -128,51 +153,57 @@ show_score(void) char s[16]; int r = snprintf(s, 16, "Time: "); snprintscore(s+r, 16-r, score); - SFont_Write(surf_screen, g_font, XSIZE-250, 0, s); + font_write(XSIZE-250, 0, s); } void -display_scores(SDL_Surface *s, uint32_t x, uint32_t y) +display_scores(uint32_t x, uint32_t y) { char t[1024]; - int i,h = SFont_TextHeight(g_font); + int i,h = font_height(); + int display_cursor = (SDL_GetTicks() / CURSOR_BLINK_TIME) % 2; - SFont_Write(s,g_font,x+30,y,"High scores"); + + font_write(x+30, y, "High scores"); y += h; + if(g_easy) font_write(x+75,y,"(easy)"); + else font_write(x+60,y,"(normal)"); for(i = 0; i 0) name[--n]=0; - } else { - if(k == SDLK_RETURN) { - SDL_EnableUNICODE(0); - cur_score = -1; - return false; - } else name[n++] = c; - } + if(key->sym == SDLK_BACKSPACE) { + if(n > 0) name[--n]=0; + } else { + if(key->sym == SDLK_RETURN || key->sym == SDLK_KP_ENTER) { + SDL_EnableUNICODE(0); + cur_score = -1; + if(n == 0) { + name[0] = '-'; + } + return false; + } else if(n < 12) { + if(key->unicode >= 32 && key->unicode <= 126) { + name[n++] = key->unicode; + } + } // else drop it } return true; }