Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
vor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
particle generation no longer depends on the framerate
[vor.git]
/
score.c
diff --git
a/score.c
b/score.c
index
5738e72
..
78a03ac
100644
(file)
--- a/
score.c
+++ b/
score.c
@@
-27,35
+27,54
@@
#include "common.h"
#include "config.h"
#include "file.h"
#include "common.h"
#include "config.h"
#include "file.h"
+#include "globals.h"
#include "score.h"
// High score table
#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,"-"}
+ }
};
};
+static char *titles[2] = { "Normal\n", "Easy\n" };
+
extern SFont_Font *g_font;
extern SFont_Font *g_font;
+int g_easy = 0;
int cur_score = -1; // which score we're currently entering.
void
read_high_score_table()
{
FILE *f;
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
f = open_score_file("r");
if(f) {
// If the file exists, read from it
- for(i = 0; i<N_SCORES; i++) {
- fscanf(f, "%d %31[^\n]", &g_scores[i].score, g_scores[i].name);
+ for(j=0; j<2; j++) {
+ fscanf(f, titles[j]);
+ for(i = 0; i<N_SCORES; i++) {
+ fscanf(f, "%d %31[^\n]\n", &g_scores[j][i].score, g_scores[j][i].name);
+ }
}
fclose(f);
}
}
fclose(f);
}
@@
-65,13
+84,16
@@
void
write_high_score_table()
{
FILE *f;
write_high_score_table()
{
FILE *f;
- int i;
+ int i, j;
f = open_score_file("w");
if(f) {
// If the file exists, write to it
f = open_score_file("w");
if(f) {
// If the file exists, write to it
- for(i = 0; i<N_SCORES; i++) {
- fprintf (f, "%d %.31s\n", g_scores[i].score, g_scores[i].name);
+ for(j=0; j<2; j++) {
+ fprintf(f, titles[j]);
+ for(i = 0; i<N_SCORES; i++) {
+ fprintf (f, "%d %.31s\n", g_scores[j][i].score, g_scores[j][i].name);
+ }
}
fclose(f);
}
}
fclose(f);
}
@@
-83,7
+105,7
@@
score_rank(int score)
int i;
for(i=0; i<N_SCORES; i++) {
int i;
for(i=0; i<N_SCORES; i++) {
- if(score > g_scores[i].score) return i;
+ if(score > g_scores[g_easy][i].score) return i;
}
return -1;
}
}
return -1;
}
@@
-91,20
+113,26
@@
score_rank(int score)
int
new_high_score(int score)
{
int
new_high_score(int score)
{
- int i;
-
cur_score = -1; // assume not a new high score
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);
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.
// 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.
// 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;
}
return true;
}
@@
-121,11
+149,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
}
void
@@
-136,40
+166,37
@@
display_scores(SDL_Surface *s, uint32_t x, uint32_t y)
SFont_Write(s,g_font,x+30,y,"High scores");
y += h;
SFont_Write(s,g_font,x+30,y,"High scores");
y += h;
+ if(g_easy) SFont_Write(s,g_font,x+75,y,"(easy)");
+ else SFont_Write(s,g_font,x+60,y,"(normal)");
for(i = 0; i<N_SCORES; i++) {
y += h;
snprintf(t, 1024, "#%1d",i+1);
SFont_Write(s, g_font, x, y, t);
for(i = 0; i<N_SCORES; i++) {
y += h;
snprintf(t, 1024, "#%1d",i+1);
SFont_Write(s, g_font, x, y, t);
- snprintscore(t, 1024, g_scores[i].score);
+ snprintscore(t, 1024, g_scores[g_easy][i].score);
SFont_Write(s, g_font, x+50, y, t);
SFont_Write(s, g_font, x+50, y, t);
- if(i == cur_score) snprintf(t, 1024, "%s_", g_scores[i].name);
- else snprintf(t, 1024, "%s", g_scores[i].name);
+ if(i == cur_score) snprintf(t, 1024, "%s_", g_scores[g_easy][i].name);
+ else snprintf(t, 1024, "%s", g_scores[g_easy][i].name);
SFont_Write(s, g_font, x+180, y, t);
}
}
int
SFont_Write(s, g_font, x+180, y, t);
}
}
int
-process_score_input(void)
+process_score_input(SDL_keysym *key)
{
char *name;
{
char *name;
- int c,k,n;
- SDL_Event e;
+ int n;
- name = g_scores[cur_score].name;
+ name = g_scores[g_easy][cur_score].name;
n = strlen(name);
n = strlen(name);
- while(SDL_PollEvent(&e) && e.type == SDL_KEYDOWN) {
- c = e.key.keysym.unicode;
- k = e.key.keysym.sym;
- 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;
- }
+ if(key->sym == SDLK_BACKSPACE) {
+ if(n > 0) name[--n]=0;
+ } else {
+ if(key->sym == SDLK_RETURN) {
+ SDL_EnableUNICODE(0);
+ cur_score = -1;
+ return false;
+ } else name[n++] = key->unicode;
}
return true;
}
}
return true;
}