X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsupertux%2Fgame_session.cpp;h=d29300d922ae8595aec68890eb3977dec813d2c5;hb=590805b8b24971ca43f777abfbf79fce21792804;hp=efe4c78d16886f23a6e232ff31ef8e3905e1550a;hpb=26316f3548bc819f817918a79dbee7ce9f7270c5;p=supertux.git diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index efe4c78d1..d29300d92 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -75,14 +75,15 @@ GameSession::GameSession(const std::string& levelfile_, Savegame& savegame, Stat coins_at_start(), bonus_at_start(), max_fire_bullets_at_start(), - max_ice_bullets_at_start() + max_ice_bullets_at_start(), + active(false) { if (restart_level() != 0) throw std::runtime_error ("Initializing the level failed."); } int -GameSession::restart_level() +GameSession::restart_level(bool after_death) { PlayerStatus* currentStatus = m_savegame.get_player_status(); coins_at_start = currentStatus->coins; @@ -130,9 +131,13 @@ GameSession::restart_level() ScreenManager::current()->pop_screen(); return (-1); } - - SoundManager::current()->stop_music(); - currentsector->play_music(LEVEL_MUSIC); + if(after_death == true) { + currentsector->resume_music(); + } + else { + SoundManager::current()->stop_music(); + currentsector->play_music(LEVEL_MUSIC); + } if(capture_file != "") { int newSeed=0; // next run uses a new seed @@ -249,6 +254,7 @@ GameSession::toggle_pause() speed_before_pause = ScreenManager::current()->get_speed(); ScreenManager::current()->set_speed(0); MenuManager::instance().set_menu(MenuStorage::GAME_MENU); + SoundManager::current()->pause_music(); game_pause = true; } @@ -267,6 +273,12 @@ GameSession::abort_level() currentStatus->max_ice_bullets = max_ice_bullets_at_start; } +bool +GameSession::is_active() const +{ + return !game_pause && active; +} + void GameSession::set_editmode(bool edit_mode_) { @@ -370,7 +382,7 @@ GameSession::check_end_conditions() if(end_sequence && end_sequence->is_done()) { finish(true); } else if (!end_sequence && tux->is_dead()) { - restart_level(); + restart_level(true); } } @@ -406,6 +418,7 @@ GameSession::setup() int total_stats_to_be_collected = level->stats.total_coins + level->stats.total_badguys + level->stats.total_secrets; if ((!levelintro_shown) && (total_stats_to_be_collected > 0)) { levelintro_shown = true; + active = false; ScreenManager::current()->push_screen(std::unique_ptr(new LevelIntro(level.get(), best_level_statistics))); } } @@ -418,6 +431,11 @@ GameSession::leave() void GameSession::update(float elapsed_time) { + // Set active flag + if(!active) + { + active = true; + } // handle controller if(InputManager::current()->get_controller()->pressed(Controller::ESCAPE) || InputManager::current()->get_controller()->pressed(Controller::START)) @@ -440,6 +458,7 @@ GameSession::update(float elapsed_time) // Unpause the game if the menu has been closed if (game_pause && !MenuManager::instance().is_active()) { ScreenManager::current()->set_speed(speed_before_pause); + SoundManager::current()->resume_music(); game_pause = false; } @@ -478,8 +497,11 @@ GameSession::update(float elapsed_time) } } + if(currentsector == NULL) + return; + // update sounds - if (currentsector && currentsector->camera) SoundManager::current()->set_listener_position(currentsector->camera->get_center()); + if (currentsector->camera) SoundManager::current()->set_listener_position(currentsector->camera->get_center()); /* Handle music: */ if (end_sequence)