Fade out and pause music on death and resume on restart of level, fixes #1064
[supertux.git] / src / supertux / game_session.cpp
index efe4c78..da864e2 100644 (file)
@@ -82,7 +82,7 @@ GameSession::GameSession(const std::string& levelfile_, Savegame& savegame, Stat
 }
 
 int
-GameSession::restart_level()
+GameSession::restart_level(bool after_death)
 {
     PlayerStatus* currentStatus = m_savegame.get_player_status();
     coins_at_start = currentStatus->coins;
@@ -130,9 +130,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 +253,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;
   }
 
@@ -370,7 +375,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);
   }
 }
 
@@ -440,6 +445,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 +484,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)