fixed game load/save
authorTobias Gläßer <tobi.web@gmx.de>
Mon, 8 Mar 2004 15:17:56 +0000 (15:17 +0000)
committerTobias Gläßer <tobi.web@gmx.de>
Mon, 8 Mar 2004 15:17:56 +0000 (15:17 +0000)
SVN-Revision: 191

src/gameloop.c
src/setup.c
src/timer.c
src/timer.h
src/title.c

index 04043f8..446852e 100644 (file)
@@ -305,18 +305,18 @@ int game_action(void)
           level++;
           next_level = 0;
           if(st_gl_mode != ST_GL_TEST)
-         {
-            drawresultscreen();
-         }
-         else
-         {
-             level_free_gfx();
+            {
+              drawresultscreen();
+            }
+          else
+            {
+              level_free_gfx();
               level_free(&current_level);
               level_free_song();
               unloadshared();
               arrays_free();
               return(0);
-         }
+            }
           player_level_begin(&tux);
         }
       else
@@ -350,7 +350,7 @@ int game_action(void)
       set_defaults();
       level_free(&current_level);
       if(level_load(&current_level,level_subset,level) != 0)
-        exit(1);
+        return 0;
       arrays_free();
       arrays_init();
       activate_bad_guys();
@@ -564,27 +564,23 @@ int gameloop(char * subset, int levelnb, int mode)
   timer_type fps_timer, frame_timer;
   timer_init(&fps_timer, YES);
   timer_init(&frame_timer, YES);
-  
+
   game_started = YES;
 
   st_gl_mode = mode;
   level = levelnb;
   strcpy(level_subset,subset);
 
-  if(st_gl_mode != ST_GL_LOAD_GAME)
-    {
-      /* Init the game: */
-      arrays_init();
-      set_defaults();
+  /* Init the game: */
+  arrays_init();
+  set_defaults();
 
-      if(level_load(&current_level,level_subset,level) != 0)
-        exit(1);
-      level_load_gfx(&current_level);
-      activate_bad_guys();
-      level_load_song(&current_level);
+  if(level_load(&current_level,level_subset,level) != 0)
+    exit(1);
+  level_load_gfx(&current_level);
+  activate_bad_guys();
+  level_load_song(&current_level);
 
-    }
-    
   player_init(&tux);
 
   if(st_gl_mode != ST_GL_TEST)
@@ -596,7 +592,7 @@ int gameloop(char * subset, int levelnb, int mode)
     levelintro();
 
 
-    timer_init(&time_left,YES);
+  timer_init(&time_left,YES);
   start_timers();
 
   if(st_gl_mode == ST_GL_LOAD_GAME)
@@ -640,7 +636,7 @@ int gameloop(char * subset, int levelnb, int mode)
       /* Handle events: */
 
       tux.input.old_fire = tux.input.fire;
-      
+
       game_event();
 
       if(show_menu)
@@ -1742,9 +1738,15 @@ void savegame(int slot)
       fwrite(&level,sizeof(int),1,fi);
       fwrite(&score,sizeof(int),1,fi);
       fwrite(&distros,sizeof(int),1,fi);
-      fwrite(&tux,sizeof(player_type),1,fi);
       fwrite(&scroll_x,sizeof(float),1,fi);
-      fwrite(&time_left,sizeof(float),1,fi);
+      fwrite(&tux,sizeof(player_type),1,fi);
+      timer_fwrite(&tux.invincible_timer,fi);
+      printf("Time inv LEFT: %d\n",timer_get_left(&tux.invincible_timer));
+      timer_fwrite(&tux.skidding_timer,fi);
+      timer_fwrite(&tux.safe_timer,fi);
+      timer_fwrite(&tux.frame_timer,fi);
+      timer_fwrite(&time_left,fi);
+      printf("Time LEFT: %d\n",timer_get_left(&time_left));
       ui = st_get_ticks();
       fwrite(&ui,sizeof(int),1,fi);
     }
@@ -1789,20 +1791,20 @@ void loadgame(int slot)
       level_free_song();
       level_load_song(&current_level);
       levelintro();
-      timer_start(&time_left,current_level.time_left*1000);
       update_time = st_get_ticks();
 
       fread(&score,sizeof(int),1,fi);
       fread(&distros,sizeof(int),1,fi);
-      fread(&tux,sizeof(player_type),1,fi);
       fread(&scroll_x,sizeof(float),1,fi);
-      fread(&time_left,sizeof(float),1,fi);
+      fread(&tux,sizeof(player_type),1,fi);
+      timer_fread(&tux.invincible_timer,fi);
+      printf("Time inv LEFT: %d - %d\n",timer_get_left(&tux.invincible_timer),tux.invincible_timer.time);
+      timer_fread(&tux.skidding_timer,fi);
+      timer_fread(&tux.safe_timer,fi);
+      timer_fread(&tux.frame_timer,fi);
+      timer_fread(&time_left,fi);
+      printf("Time LEFT: %d\n",timer_get_left(&time_left));
       fread(&ui,sizeof(int),1,fi);
-      time_left.time += st_get_ticks() - ui;
-      tux.invincible_timer.time += st_get_ticks() - ui;
-      tux.skidding_timer.time += st_get_ticks() - ui;
-      tux.safe_timer.time += st_get_ticks() - ui;
-      tux.vphysic.start_time += st_get_ticks() - ui;
       tux.hphysic.start_time += st_get_ticks() - ui;
       tux.vphysic.start_time += st_get_ticks() - ui;
       fclose(fi);
index 4a68ce4..2f7e48c 100644 (file)
@@ -392,7 +392,11 @@ void process_save_load_game_menu(int save)
           else
             {
               if(game_started == NO)
-                gameloop("whatever",slot,ST_GL_LOAD_GAME);
+             {
+                gameloop("default",slot,ST_GL_LOAD_GAME);
+               show_menu = YES;
+               menu_set_current(&main_menu);
+               }
               else
                 loadgame(slot);
             }
index 2e5b458..25a63a3 100644 (file)
@@ -1,7 +1,7 @@
 //
 // C Implementation: timer
 //
-// Description: 
+// Description:
 //
 //
 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
@@ -18,39 +18,39 @@ unsigned int st_pause_ticks, st_pause_count;
 
 unsigned int st_get_ticks(void)
 {
-if(st_pause_count != 0)
-return SDL_GetTicks() - st_pause_ticks - SDL_GetTicks() + st_pause_count;
-else
-return SDL_GetTicks() - st_pause_ticks;
+  if(st_pause_count != 0)
+    return SDL_GetTicks() - st_pause_ticks - SDL_GetTicks() + st_pause_count;
+  else
+    return SDL_GetTicks() - st_pause_ticks;
 }
 
 void st_pause_ticks_init(void)
 {
-st_pause_ticks = 0;
-st_pause_count = 0;
+  st_pause_ticks = 0;
+  st_pause_count = 0;
 }
 
 void st_pause_ticks_start(void)
 {
-st_pause_count = SDL_GetTicks();
+  st_pause_count = SDL_GetTicks();
 }
 
 void st_pause_ticks_stop(void)
 {
-st_pause_ticks += SDL_GetTicks() - st_pause_count;
-st_pause_count = 0;
+  st_pause_ticks += SDL_GetTicks() - st_pause_count;
+  st_pause_count = 0;
 }
 
 void timer_init(timer_type* ptimer, int st_ticks)
 {
   ptimer->period = 0;
   ptimer->time = 0;
-  
+
   if(st_ticks == YES)
-  ptimer->get_ticks = st_get_ticks;
+    ptimer->get_ticks = st_get_ticks;
   else
-  ptimer->get_ticks = SDL_GetTicks;
+    ptimer->get_ticks = SDL_GetTicks;
+
 }
 
 void timer_start(timer_type* ptimer, unsigned int period)
@@ -61,10 +61,10 @@ void timer_start(timer_type* ptimer, unsigned int period)
 
 void timer_stop(timer_type* ptimer)
 {
-if(ptimer->get_ticks == st_get_ticks)
- timer_init(ptimer,YES);
-else
- timer_init(ptimer,NO);
+  if(ptimer->get_ticks == st_get_ticks)
   timer_init(ptimer,YES);
+  else
   timer_init(ptimer,NO);
 }
 
 int timer_check(timer_type* ptimer)
@@ -95,3 +95,40 @@ int timer_get_gone(timer_type* ptimer)
 {
   return (ptimer->get_ticks() - ptimer->time);
 }
+
+int timer_fwrite(timer_type* ptimer, FILE* fi)
+{
+  unsigned int diff_ticks;
+  int tick_mode;
+  if(ptimer->time != 0)
+    diff_ticks = ptimer->get_ticks() - ptimer->time;
+  else
+    diff_ticks = 0;
+
+  fwrite(&ptimer->period,sizeof(unsigned int),1,fi);
+  fwrite(&diff_ticks,sizeof(unsigned int),1,fi);
+  if(ptimer->get_ticks == st_get_ticks)
+      tick_mode = YES;
+  else
+      tick_mode = NO;
+  fwrite(&tick_mode,sizeof(unsigned int),1,fi);
+}
+
+int timer_fread(timer_type* ptimer, FILE* fi)
+{
+  unsigned int diff_ticks;
+  int tick_mode;
+  fread(&ptimer->period,sizeof(unsigned int),1,fi);
+  fread(&diff_ticks,sizeof(unsigned int),1,fi);
+  fread(&tick_mode,sizeof(unsigned int),1,fi);
+  if(tick_mode == YES)
+    ptimer->get_ticks = st_get_ticks;
+  else
+    ptimer->get_ticks = SDL_GetTicks;
+  if(diff_ticks != 0)
+    ptimer->time = ptimer->get_ticks() - diff_ticks;
+  else
+    ptimer->time = 0;
+
+}
+
index 8cd880a..f2f1823 100644 (file)
@@ -50,6 +50,8 @@ int timer_started(timer_type* ptimer);
 ======================================================================*/
 int timer_get_left(timer_type* ptimer);
 int timer_get_gone(timer_type* ptimer);
+int timer_fwrite(timer_type* ptimer, FILE* fi);
+int timer_fread(timer_type* ptimer, FILE* fi);
 
 #endif /*SUPERTUX_TIMER_H*/
 
index 666c5a9..362abeb 100644 (file)
@@ -282,7 +282,7 @@ void display_credits()
   int done;
   int scroll, speed;
   timer_type timer;
-  int n,d;
+  int n,d,e;
   int length;
   FILE* fi;
   char temp[1024];
@@ -316,6 +316,7 @@ void display_credits()
   done = 0;
 
   n = d = 0;
+  e = -20;
 
   length = names.num_items;
 
@@ -372,12 +373,18 @@ void display_credits()
               else if(names.item[i][0] == '    ')
                 text_drawf(&white_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
               else if(names.item[i+1][0] == '-' || names.item[i][0] == '-')
-                text_drawf(&white_big_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
+                text_drawf(&white_big_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 3+e%7, NO_UPDATE);
               else
-                text_drawf(&blue_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
+                text_drawf(&blue_text, names.item[i], 0 + e % 20, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
             }
         }
-
+      if(e == 20)
+      {
+      e = -19;
+      }
+      e++;
+      
+      
       texture_draw_part(&bkg_title, 0, 0, 0, 0, 640, 130, NO_UPDATE);
 
       flipscreen();
@@ -389,7 +396,7 @@ void display_credits()
       if(scroll < 0)
         scroll = 0;
 
-      SDL_Delay(20);
+      SDL_Delay(35);
 
       if(timer_get_left(&timer) < 0)
         {