JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
slightly less half-assed event handling
authorJoshua Grams <josh@qualdan.com>
Wed, 12 Apr 2006 19:13:07 +0000 (19:13 +0000)
committerJoshua Grams <josh@qualdan.com>
Wed, 12 Apr 2006 19:13:07 +0000 (19:13 +0000)
removed message fades on windows

main.c
score.c
score.h

diff --git a/main.c b/main.c
index 3f4486b..01fcc13 100644 (file)
--- a/main.c
+++ b/main.c
 #include "sprite.h"
 #include "sound.h"
 
+#ifdef WIN32
+#define SetAlpha(surf, flag, alpha)
+#endif
+
 // ************************************* VARS
 // SDL_Surface global variables
 SDL_Surface 
@@ -526,17 +530,6 @@ draw(void) {
 
                case HIGH_SCORE_ENTRY:
                        play_tune(TUNE_HIGH_SCORE_ENTRY);
-                       if(!process_score_input()) {  // done inputting name
-
-                               // Change state to briefly show high scores page
-                               state = HIGH_SCORE_DISPLAY;
-                               state_timeout = 200;
-
-                               // Write the high score table to the file
-                               write_high_score_table();
-               
-                               play_tune(TUNE_TITLE_PAGE);
-                       }
                // FALL THROUGH TO
                case HIGH_SCORE_DISPLAY:
                        // Display de list o high scores mon.
@@ -594,7 +587,25 @@ gameloop() {
 
        for(;;) {
                while(SDL_PollEvent(&e)) {
-                       if(e.type == SDL_QUIT) return;
+                       switch(e.type) {
+                               case SDL_QUIT: return;
+                               case SDL_KEYUP:
+                                       if(e.key.keysym.sym == SDLK_ESCAPE
+                                          || e.key.keysym.sym == SDLK_q)
+                                               return;
+                                       break;
+                               case SDL_KEYDOWN:
+                                       if(state == HIGH_SCORE_ENTRY)
+                                               if(!process_score_input(&e.key.keysym)) {
+                                                       // Write the high score table to the file
+                                                       write_high_score_table();
+                                                       // continue to display the scores briefly
+                                                       state = HIGH_SCORE_DISPLAY;
+                                                       state_timeout = 200;
+                                                       play_tune(TUNE_TITLE_PAGE);
+                                               }
+                                       break;
+                       }
                }
                keystate = SDL_GetKeyState(NULL);
 
@@ -757,10 +768,6 @@ gameloop() {
                        state = HIGH_SCORE_DISPLAY;
                        state_timeout = 400;
                }
-
-               if(state != HIGH_SCORE_ENTRY && (keystate[SDLK_q] || keystate[SDLK_ESCAPE]))
-                       return;
-
        }
 }
 
diff --git a/score.c b/score.c
index 406576c..78a03ac 100644 (file)
--- a/score.c
+++ b/score.c
@@ -181,27 +181,22 @@ display_scores(SDL_Surface *s, uint32_t x, uint32_t y)
 }
 
 int
-process_score_input(void)
+process_score_input(SDL_keysym *key)
 {
        char *name;
-       int c,k,n;
-       SDL_Event e;
+       int n;
        
        name = g_scores[g_easy][cur_score].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;
 }
diff --git a/score.h b/score.h
index b64e119..6473260 100644 (file)
--- a/score.h
+++ b/score.h
@@ -40,6 +40,6 @@ void show_score(void);
 void display_scores(SDL_Surface *s, uint32_t x, uint32_t y);
 int new_high_score(int score);
 int insert_score(int score);
-int process_score_input(void);
+int process_score_input(SDL_keysym *key);
 
 #endif // VOR_SCORE_H