- fixed bug in live counting
[supertux.git] / src / gameloop.cpp
index f8b96eb..5e86022 100644 (file)
@@ -10,6 +10,7 @@
   April 11, 2000 - March 15, 2004
 */
 
+#include <iostream>
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -62,6 +63,8 @@ GameSession::restart_level()
   fps_timer.init(true);
   frame_timer.init(true);
 
+  delete world;
+
   if (st_gl_mode == ST_GL_LOAD_LEVEL_FILE)
     {
       world = new World(subset);
@@ -134,8 +137,7 @@ GameSession::process_events()
   while (SDL_PollEvent(&event))
     {
       /* Check for menu-events, if the menu is shown */
-      if(show_menu)
-        current_menu->event(event);
+      current_menu->event(event);
 
       switch(event.type)
         {
@@ -159,7 +161,7 @@ GameSession::process_events()
                       {
                         exit_status = LEVEL_ABORT;
                       }
-                    else if(show_menu)
+                    else if(!show_menu)
                       {
                         Menu::set_current(game_menu);
                         show_menu = 0;
@@ -317,7 +319,8 @@ GameSession::check_end_conditions()
       // Check End conditions
       if (tux->is_dead())
         {
-          
+          player_status.lives -= 1;             
+    
           if (player_status.lives < 0)
             { // No more lives!?
               if(st_gl_mode != ST_GL_TEST)
@@ -325,8 +328,10 @@ GameSession::check_end_conditions()
           
               if(st_gl_mode != ST_GL_TEST)
                 {
-                  if (player_status.score > hs_score)
-                    save_hs(player_status.score);
+                  // FIXME: highscore soving doesn't make sense in its
+                  // current form
+                  //if (player_status.score > hs_score)
+                  //save_hs(player_status.score);
                 }
               
               exit_status = GAME_OVER;
@@ -346,10 +351,7 @@ GameSession::action(double frame_ratio)
   
   if (exit_status == NONE)
     {
-      Player* tux = world->get_tux();
-      
       // Update Tux and the World
-      tux->action(frame_ratio);
       world->action(frame_ratio);
     }
 }
@@ -411,12 +413,11 @@ GameSession::run()
 
   draw();
 
+  float overlap = 0.0f;
   while (exit_status == NONE)
     {
       /* Calculate the movement-factor */
       double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
-      if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */
-        frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85;
 
       if(!frame_timer.check())
         {
@@ -438,14 +439,7 @@ GameSession::run()
                 case 2:
                   st_pause_ticks_stop();
                   break;
-                case 3:
-                  // FIXME:
-                  //update_load_save_game_menu(save_game_menu);
-                  break;
-                case 4:
-                  update_load_save_game_menu(load_game_menu);
-                  break;
-                case 7:
+                case 5:
                   st_pause_ticks_stop();
                   exit_status = LEVEL_ABORT;
                   break;
@@ -464,7 +458,15 @@ GameSession::run()
       // Handle actions:
       if(!game_pause && !show_menu)
         {
-          action(frame_ratio);
+          frame_ratio *= game_speed;
+          frame_ratio += overlap;
+          while (frame_ratio > 0)
+            {
+              action(1.0f);
+              frame_ratio -= 1.0f;
+            }
+          overlap = frame_ratio;
+
           if (exit_status != NONE)
             return exit_status;
         }