JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fixed messages
[vor.git] / score.c
diff --git a/score.c b/score.c
index ac619dd..77e8ab3 100644 (file)
--- a/score.c
+++ b/score.c
@@ -1,31 +1,50 @@
-#include "config.h"
-
-#include "SFont.h"
-#include "file.h"
-#include "score.h"
+/* Variations on RockDodger
+ * Copyright (C) 2004 Joshua Grams <josh@qualdan.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
 
 #include <SDL.h>
 #include <SDL_keysym.h>
-#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "SFont.h"
+
+#include "common.h"
+#include "config.h"
+#include "file.h"
+#include "globals.h"
+#include "score.h"
+
 // High score table
 struct highscore g_scores[N_SCORES] = {
-       {13000,"Pad"},
-       {12500,"Pad"},
-       {6500,"Pad"},
-       {5000,"Pad"},
-       {3000,"Pad"},
-       {2500,"Pad"},
-       {2000,"Pad"},
-       {1500,"Pad"}
+       {1*60*1000,"-"},
+       {45*1000,"-"},
+       {30*1000,"-"},
+       {20*1000,"-"},
+       {10*1000,"-"},
+       {7*1000,"-"},
+       {5*1000,"-"},
+       {3*1000,"-"}
 };
 
 extern SFont_Font *g_font;
 
-int cur_score; // which score we're currently entering.
+int cur_score = -1; // which score we're currently entering.
 
 void
 read_high_score_table()
@@ -37,8 +56,6 @@ read_high_score_table()
        if(f) {
                // If the file exists, read from it
                for(i = 0; i<N_SCORES; i++) {
-                       g_scores[i].score = 0;
-                       g_scores[i].name[0] = 0;
                        fscanf(f, "%d %31[^\n]", &g_scores[i].score, g_scores[i].name);
                }
                fclose(f);
@@ -105,11 +122,13 @@ snprintscore(char *s, size_t n, int score)
        }
 }
 
-int
-snprintscore_line(char *s, size_t n, int score)
+void
+show_score(void)
 {
-       int r = snprintf(s, n, "Time: ");
-       return r + snprintscore(s+r, n-r, score);
+       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);
 }
 
 void
@@ -126,7 +145,8 @@ display_scores(SDL_Surface *s, uint32_t x, uint32_t y)
                SFont_Write(s, g_font, x, y, t);
                snprintscore(t, 1024, g_scores[i].score);
                SFont_Write(s, g_font, x+50, y, t);
-               snprintf(t, 1024, "%s", g_scores[i].name);
+               if(i == cur_score) snprintf(t, 1024, "%s_", g_scores[i].name);
+               else snprintf(t, 1024, "%s", g_scores[i].name);
                SFont_Write(s, g_font, x+180, y, t);
        }
 }
@@ -144,12 +164,15 @@ process_score_input(void)
        while(SDL_PollEvent(&e) && e.type == SDL_KEYDOWN) {
                c = e.key.keysym.unicode;
                k = e.key.keysym.sym;
-               if(k == SDLK_BACKSPACE && n > 0) name[n--]=0;
-               else if(e.key.keysym.sym == SDLK_RETURN) {
-                       SDL_EnableUNICODE(0);
-                       return false;
+               if(k == SDLK_BACKSPACE) {
+                       if(n > 0) name[--n]=0;
+               } else {
+                       if(k == SDLK_RETURN) {
+                               SDL_EnableUNICODE(0);
+                               cur_score = -1;
+                               return false;
+                       } else name[n++] = c;
                }
-               else name[n++] = c;
        }
        return true;
 }