Added high score code by Adam Czachorowski.
authorBill Kendrick <nbs@sonic.net>
Wed, 10 Dec 2003 08:16:46 +0000 (08:16 +0000)
committerBill Kendrick <nbs@sonic.net>
Wed, 10 Dec 2003 08:16:46 +0000 (08:16 +0000)
SVN-Revision: 11

Makefile
src/gameloop.c
src/title.c

index c66631e..ff1cc35 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
 
 # Version 0.0.5
 
-# April 11, 2000 - December 9, 2003
+# April 11, 2000 - December 10, 2003
 
 
 # User-definable stuff:
@@ -39,7 +39,7 @@ installdat = install -g root -o root -m 644
 
 
 OBJECTS=obj/supertux.o obj/setup.o obj/intro.o obj/title.o obj/gameloop.o \
-       obj/screen.o obj/sound.o
+       obj/screen.o obj/sound.o obj/high_scores.o
 
 # Make commands:
 
@@ -105,3 +105,8 @@ obj/screen.o:       src/screen.c src/defines.h src/globals.h src/screen.h
 
 obj/sound.o:   src/sound.c src/defines.h src/globals.h src/sound.h
        $(CC) $(CFLAGS) src/sound.c -c -o obj/sound.o
+
+obj/high_scores.o:     src/high_scores.c src/defines.h src/globals.h \
+                       src/sound.h
+       $(CC) $(CFLAGS) src/high_scores.c -c -o obj/high_scores.o
+
index a316fea..772386e 100644 (file)
@@ -34,6 +34,7 @@
 #include "screen.h"
 #include "sound.h"
 #include "setup.h"
+#include "high_scores.h"
 
 
 /* Sound files: */
@@ -78,7 +79,7 @@ char * soundfilenames[NUM_SOUNDS] = {
 
 /* Local variables: */
 
-int score, distros, level, lives, scroll_x, next_level,
+int score, highscore, distros, level, lives, scroll_x, next_level,
   tux_dir, tux_size, tux_duck, tux_x, tux_xm, tux_y, tux_ym,
   tux_dying, tux_safe, jumping, jump_counter, frame, score_multiplier,
   tux_frame_main, tux_frame, tux_got_coffee, tux_skidding,
@@ -154,6 +155,7 @@ void trybumpbadguy(int x, int y, int sx);
 void add_upgrade(int x, int y, int kind);
 void killtux(int mode);
 void add_bullet(int x, int y, int dir, int xm);
+void drawendscreen(void);
 
 
 /* --- GAME LOOP! --- */
@@ -181,6 +183,7 @@ int gameloop(void)
   loadlevel();
   loadlevelgfx();
   loadlevelsong();
+  highscore = load_hs();
   
   
   /* --- MAIN GAME LOOP!!! --- */
@@ -549,34 +552,14 @@ int gameloop(void)
              
              /* No more lives!? */
 
-             if (lives <= 0)
+             if (lives < 0)
              {
+                drawendscreen();
 
+               if (score > highscore)
+                 save_hs(score);
 
-               /* Display end-of-level stuff */
-               /* (FIXME: This should go in its own event loop function!) */
-               
-               clearscreen(0, 0, 0);
-
-               drawcenteredtext("GAMEOVER", 200, letters_red, NO_UPDATE);
-
-               sprintf(str, "SCORE: %d", score);
-               drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
-
-               sprintf(str, "DISTROS: %d", distros);
-               drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
-
-               SDL_Flip(screen);
-               SDL_Delay(5000);
-
-
-               /* FIXME: Should return to title screen, not restart game... */
-               
-               level = 0;
-               lives = 3;
-               
-               score=0;
-               distros=0;
+               return(0);
              }
              
              
@@ -2146,6 +2129,10 @@ int gameloop(void)
       sprintf(str, "%d", score);
       drawtext("SCORE", 0, 0, letters_blue, NO_UPDATE);
       drawtext(str, 96, 0, letters_gold, NO_UPDATE);
+
+      sprintf(str, "%d", highscore);
+      drawtext("HIGH", 0, 20, letters_blue, NO_UPDATE);
+      drawtext(str, 80, 20, letters_gold, NO_UPDATE);
       
       if (time_left >= 50 || (frame % 10) < 5)
        {
@@ -3542,4 +3529,23 @@ void add_bullet(int x, int y, int dir, int xm)
       playsound(sounds[SND_SHOOT]);
 #endif
     }
+
+
+void drawendscreen(void)
+{
+  char str[80];
+  
+  clearscreen(0, 0, 0);
+
+  drawcenteredtext("GAMEOVER", 200, letters_red, NO_UPDATE);
+
+  sprintf(str, "SCORE: %d", score);
+  drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
+
+  sprintf(str, "DISTROS: %d", distros);
+  drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
+
+  SDL_Flip(screen);
+  SDL_Delay(2000);
 }
+
index 831a2d9..5de4bb8 100644 (file)
@@ -7,7 +7,7 @@
   bill@newbreedsoftware.com
   http://www.newbreedsoftware.com/supertux/
   
-  April 11, 2000 - April 12, 2000
+  April 11, 2000 - December 9, 2003
 */
 
 #include <stdio.h>
@@ -32,6 +32,7 @@
 #include "globals.h"
 #include "title.h"
 #include "screen.h"
+#include "high_scores.h"
 
 
 /* --- TITLE SCREEN --- */
@@ -42,6 +43,7 @@ int title(void)
   SDL_Event event;
   SDLKey key;
   int done, quit, frame, pict;
+  char str[80];
   
   
   /* Clear screen: */
@@ -62,6 +64,12 @@ int title(void)
   /* Draw the title background: */
   
   drawimage(title, 0, 0, UPDATE);
+
+
+  /* Draw the high score: */
+
+  sprintf(str, "High score: %d", load_hs());
+  drawcenteredtext(str, 460, letters_red, UPDATE);
   
   
   /* --- Main title loop: --- */