-converted remaining classes to GameObject
[supertux.git] / src / worldmap.cpp
index 17cb39d..785edab 100644 (file)
@@ -21,6 +21,7 @@
 #include <fstream>
 #include <vector>
 #include <assert.h>
+#include <unistd.h>
 #include "globals.h"
 #include "texture.h"
 #include "screen.h"
@@ -637,6 +638,8 @@ WorldMap::update(float delta)
           if (level->x == tux->get_tile_pos().x && 
               level->y == tux->get_tile_pos().y)
             {
+              PlayerStatus old_player_status = player_status;
+
               std::cout << "Enter the current level: " << level->name << std::endl;;
               GameSession session(datadir +  "/levels/" + level->name,
                                   1, ST_GL_LOAD_LEVEL_FILE);
@@ -697,15 +700,32 @@ WorldMap::update(float delta)
 
                   break;
                 case GameSession::ES_LEVEL_ABORT:
-                  // Reseting the player_status might be a worthy
-                  // consideration, but I don't think we need it
-                  // 'cause only the bad players will use it to
-                  // 'cheat' a few items and that isn't necesarry a
-                  // bad thing (ie. better they continue that way,
-                  // then stop playing the game all together since it
-                  // is to hard)
+                  /* In case the player's abort the level, keep it using the old
+                      status */
+                  player_status = old_player_status;
                   break;
                 case GameSession::ES_GAME_OVER:
+                  /* draw an end screen */
+                  /* in the future, this should make a dialog a la SuperMario, asking
+                  if the player wants to restart the world map with no score and from
+                  level 1 */
+                  char str[80];
+
+                  drawgradient(Color (0, 255, 0), Color (255, 0, 255));
+
+                  blue_text->drawf("GAMEOVER", 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, "COINS: %d", player_status.distros);
+                  gold_text->drawf(str, 0, screen->w - gold_text->w*2, A_HMIDDLE, A_TOP, 1);
+
+                  flipscreen();
+  
+                  SDL_Event event;
+                  wait_for_event(event,2000,5000,true);
+
                   quit = true;
                   player_status.reset();
                   break;
@@ -815,20 +835,20 @@ WorldMap::draw_status()
   gold_text->draw(str, 96, 0);
 
   sprintf(str, "%d", player_status.distros);
-  white_text->draw_align("COINS", 320-64, 0,  A_LEFT, A_TOP);
-  gold_text->draw_align(str, 320+64, 0, A_RIGHT, A_TOP);
+  white_text->draw_align("COINS", screen->w/2 - white_text->w*5, 0,  A_LEFT, A_TOP);
+  gold_text->draw_align(str, screen->w/2 + (white_text->w*5)/2, 0, A_RIGHT, A_TOP);
 
-  white_text->draw("LIVES", 480, 0);
+  white_text->draw("LIVES", screen->w - white_text->w*9, 0);
   if (player_status.lives >= 5)
     {
       sprintf(str, "%dx", player_status.lives);
-      gold_text->draw_align(str, 617, 0, A_RIGHT, A_TOP);
-      tux_life->draw(565+(18*3), 0);
+      gold_text->draw_align(str, screen->w - gold_text->w, 0, A_RIGHT, A_TOP);
+      tux_life->draw(screen->w - gold_text->w, 0);
     }
   else
     {
       for(int i= 0; i < player_status.lives; ++i)
-        tux_life->draw(565+(18*i),0);
+        tux_life->draw(screen->w - tux_life->w*4 +(tux_life->w*i),0);
     }
 
   if (!tux->is_moving())