From: Ondřej Hošek Date: Mon, 16 Jan 2006 20:46:12 +0000 (+0000) Subject: Time now stops when you complete a level and get into the end sequence. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=29608a58312cb5859076a8d497d149c30e637374;p=supertux.git Time now stops when you complete a level and get into the end sequence. SVN-Revision: 3003 --- diff --git a/src/game_session.cpp b/src/game_session.cpp index a63f10844..14a69d649 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -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::iterator i = currentsector->gameobjects.begin(); + i != currentsector->gameobjects.end(); ++i) + { + GameObject* obj = *i; + + LevelTime* lt = dynamic_cast (obj); + if(lt) + lt->stop(); + } + if(sequencename == "fireworks") { currentsector->add_object(new Fireworks()); } diff --git a/src/object/level_time.cpp b/src/object/level_time.cpp index 7b5a1eced..c1ad71f4b 100644 --- a/src/object/level_time.cpp +++ b/src/object/level_time.cpp @@ -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"); diff --git a/src/object/level_time.hpp b/src/object/level_time.hpp index 43dcd6d8b..5855051c3 100644 --- a/src/object/level_time.hpp +++ b/src/object/level_time.hpp @@ -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