- memleak fix and menu fix from MatzeB
[supertux.git] / src / gameloop.cpp
index b43a0a9..d956b22 100644 (file)
@@ -53,6 +53,7 @@
 #include "tile.h"
 #include "particlesystem.h"
 #include "resources.h"
+#include "music_manager.h"
 
 GameSession* GameSession::current_ = 0;
 
@@ -141,9 +142,14 @@ GameSession::~GameSession()
 void
 GameSession::levelintro(void)
 {
+  music_manager->halt_music();
+  
   char str[60];
-  /* Level Intro: */
-  clearscreen(0, 0, 0);
+  if (get_level()->img_bkgd)
+    get_level()->img_bkgd->draw(0, 0);
+  else
+    drawgradient(get_level()->bkgd_top, get_level()->bkgd_bottom);
 
   sprintf(str, "%s", world->get_level()->name.c_str());
   gold_text->drawf(str, 0, 200, A_HMIDDLE, A_TOP, 1);
@@ -173,6 +179,9 @@ GameSession::start_timers()
 void
 GameSession::on_escape_press()
 {
+  if(game_pause)
+    return;
+
   if(st_gl_mode == ST_GL_TEST)
     {
       exit_status = LEVEL_ABORT;
@@ -203,6 +212,9 @@ GameSession::process_events()
     }
   else
     {
+      if(!Menu::current() && !game_pause)
+        st_pause_ticks_stop();
+
       SDL_Event event;
       while (SDL_PollEvent(&event))
         {
@@ -216,8 +228,6 @@ GameSession::process_events()
             {
               Player& tux = *world->get_tux();
   
-              st_pause_ticks_stop();
-
               switch(event.type)
                 {
                 case SDL_QUIT:        /* Quit event - quit: */
@@ -376,7 +386,7 @@ GameSession::check_end_conditions()
     {
       end_sequenze = true;
       last_x_pos = -1;
-      halt_music();
+      music_manager->halt_music();
     }
   else
     {
@@ -450,10 +460,10 @@ GameSession::process_menu()
         {
           switch (game_menu->check())
             {
-            case 2:
+            case MNID_CONTINUE:
               st_pause_ticks_stop();
               break;
-            case 5:
+            case MNID_ABORTLEVEL:
               st_pause_ticks_stop();
               exit_status = LEVEL_ABORT;
               break;
@@ -555,7 +565,7 @@ GameSession::run()
 
       /* Handle time: */
       if (!time_left.check() && world->get_tux()->dying == DYING_NOT)
-        world->get_tux()->kill(KILL);
+        world->get_tux()->kill(Player::KILL);
 
       /* Handle music: */
       if(world->get_tux()->invincible_timer.check())
@@ -627,7 +637,7 @@ GameSession::drawstatus()
     }
 
   sprintf(str, "%d", player_status.distros);
-  white_text->draw("DISTROS", screen->h, 0, 1);
+  white_text->draw("COINS", screen->h, 0, 1);
   gold_text->draw(str, 608, 0, 1);
 
   white_text->draw("LIVES", screen->h, 20, 1);
@@ -650,7 +660,10 @@ GameSession::drawendscreen()
 {
   char str[80];
 
-  clearscreen(0, 0, 0);
+  if (get_level()->img_bkgd)
+    get_level()->img_bkgd->draw(0, 0);
+  else
+    drawgradient(get_level()->bkgd_top, get_level()->bkgd_bottom);
 
   blue_text->drawf("GAMEOVER", 0, 200, A_HMIDDLE, A_TOP, 1);
 
@@ -671,14 +684,17 @@ GameSession::drawresultscreen(void)
 {
   char str[80];
 
-  clearscreen(0, 0, 0);
+  if (get_level()->img_bkgd)
+    get_level()->img_bkgd->draw(0, 0);
+  else
+    drawgradient(get_level()->bkgd_top, get_level()->bkgd_bottom);
 
   blue_text->drawf("Result:", 0, 200, A_HMIDDLE, A_TOP, 1);
 
   sprintf(str, "SCORE: %d", player_status.score);
   gold_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1);
 
-  sprintf(str, "DISTROS: %d", player_status.distros);
+  sprintf(str, "COINS: %d", player_status.distros);
   gold_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1);
 
   flipscreen();