Time now stops when you complete a level and get into the end sequence.
authorOndřej Hošek <ondra.hosek@gmail.com>
Mon, 16 Jan 2006 20:46:12 +0000 (20:46 +0000)
committerOndřej Hošek <ondra.hosek@gmail.com>
Mon, 16 Jan 2006 20:46:12 +0000 (20:46 +0000)
SVN-Revision: 3003

src/game_session.cpp
src/object/level_time.cpp
src/object/level_time.hpp

index a63f108..14a69d6 100644 (file)
@@ -718,11 +718,22 @@ GameSession::start_sequence(const std::string& sequencename)
       return;
     
     end_sequence = ENDSEQUENCE_RUNNING;
-    endsequence_timer.start(level->extro_length); // 7 seconds until we finish the map
+    endsequence_timer.start(level->extro_length);
     last_x_pos = -1;
     sound_manager->play_music("music/" + level->extro_music, false);
     currentsector->player->invincible_timer.start(level->extro_length);
 
+    // Stop all clocks.
+    for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin();
+        i != currentsector->gameobjects.end(); ++i)
+    {
+      GameObject* obj = *i;
+      
+      LevelTime* lt = dynamic_cast<LevelTime*> (obj);
+      if(lt)
+        lt->stop();
+    }
+
     if(sequencename == "fireworks") {
       currentsector->add_object(new Fireworks());
     }
index 7b5a1ec..c1ad71f 100644 (file)
@@ -17,6 +17,7 @@
 static const float TIME_WARNING = 20;
 
 LevelTime::LevelTime(const lisp::Lisp& reader)
+: final_level_time(0.f), final_remaining_time(0.f)
 {
     float time = -1;
     lisp::ListIterator iter(&reader);
@@ -53,12 +54,12 @@ LevelTime::draw(DrawingContext& context)
 
   char str[60];
     
-  if(time_left.get_timeleft() < 0) {
+  if(get_remaining_time() < 0) {
     context.draw_text(white_text, _("TIME's UP"), Vector(SCREEN_WIDTH/2, BORDER_Y),
         CENTER_ALLIGN, LAYER_FOREGROUND1);
-  } else if (time_left.get_timeleft() > TIME_WARNING
+  } else if (get_remaining_time() > TIME_WARNING
       || int(game_time * 2.5) % 2) {
-    snprintf(str, sizeof(str), " %d", int(time_left.get_timeleft()));
+    snprintf(str, sizeof(str), " %d", int(get_remaining_time()));
     context.draw_text(white_text, _("TIME"),
         Vector(SCREEN_WIDTH/2, BORDER_Y), CENTER_ALLIGN, LAYER_FOREGROUND1);
     context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2 + 4*16, BORDER_Y),
@@ -71,13 +72,25 @@ LevelTime::draw(DrawingContext& context)
 float
 LevelTime::get_level_time()
 {
+  if (!time_left.started())
+    return final_level_time;
   return time_left.get_period();
 }
 
 float
 LevelTime::get_remaining_time()
 {
+  if (!time_left.started())
+    return final_remaining_time;
   return time_left.get_timeleft();
 }
 
+void
+LevelTime::stop()
+{
+  final_level_time = time_left.get_period();
+  final_remaining_time = time_left.get_timeleft();
+  time_left.stop();
+}
+
 IMPLEMENT_FACTORY(LevelTime, "leveltime");
index 43dcd6d..5855051 100644 (file)
@@ -13,11 +13,14 @@ public:
 
     void update(float elapsed_time);
     void draw(DrawingContext& context);
+    void stop();
     float get_level_time();
     float get_remaining_time();
 
 private:
     Timer time_left;
+    float final_level_time;
+    float final_remaining_time;
 };
 
 #endif