- More work on scripting interface
[supertux.git] / src / worldmap.cpp
index 53d8fc2..173e936 100644 (file)
 #include <sstream>
 #include <unistd.h>
 
-#include "app/globals.h"
-#include "app/gettext.h"
-#include "app/setup.h"
+#include "gettext.h"
 #include "video/surface.h"
 #include "video/screen.h"
 #include "video/drawing_context.h"
-#include "special/frame_rate.h"
+#include "sprite/sprite_manager.h"
 #include "audio/sound_manager.h"
 #include "lisp/parser.h"
 #include "lisp/lisp.h"
 #include "lisp/list_iterator.h"
 #include "lisp/writer.h"
-#include "gameloop.h"
+#include "game_session.h"
 #include "sector.h"
 #include "worldmap.h"
 #include "resources.h"
 #include "misc.h"
-#include "scene.h"
-
-#define map_message_TIME 2.8
+#include "player_status.h"
+#include "textscroller.h"
+#include "main.h"
+#include "file_system.h"
+#include "gui/menu.h"
+#include "gui/mousecursor.h"
+#include "control/joystickkeyboardcontroller.h"
 
 Menu* worldmap_menu  = 0;
 
+static const float TUXSPEED = 200;
+static const float map_message_TIME = 2.8;
+
 namespace WorldMapNS {
 
 Direction reverse_dir(Direction direction)
@@ -107,10 +112,8 @@ string_to_direction(const std::string& directory)
 Tux::Tux(WorldMap* worldmap_)
   : worldmap(worldmap_)
 {
-  largetux_sprite = new Surface(datadir +  "/images/worldmap/tux.png", true);
-  firetux_sprite = new Surface(datadir +  "/images/worldmap/firetux.png", true);
-  smalltux_sprite = new Surface(datadir +  "/images/worldmap/smalltux.png", true);
-
+  tux_sprite = sprite_manager->create("worldmaptux");
+  
   offset = 0;
   moving = false;
   tile_pos.x = worldmap->get_start_x();
@@ -121,30 +124,31 @@ Tux::Tux(WorldMap* worldmap_)
 
 Tux::~Tux()
 {
-  delete smalltux_sprite;
-  delete firetux_sprite;
-  delete largetux_sprite;
+  delete tux_sprite;
 }
 
 void
-Tux::draw(DrawingContext& context, const Vector& offset)
+Tux::draw(DrawingContext& context)
 {
-  Vector pos = get_pos();
-  switch (player_status.bonus)
-    {
-    case PlayerStatus::GROWUP_BONUS:
-      context.draw_surface(largetux_sprite,
-          Vector(pos.x + offset.x, pos.y + offset.y - 10), LAYER_OBJECTS);
+  switch (player_status.bonus) {
+    case GROWUP_BONUS:
+      tux_sprite->set_action("large");
       break;
-    case PlayerStatus::FLOWER_BONUS:
-      context.draw_surface(firetux_sprite,
-          Vector(pos.x + offset.x, pos.y + offset.y - 10), LAYER_OBJECTS);
+    case FIRE_BONUS:
+      tux_sprite->set_action("fire");
       break;
-    case PlayerStatus::NO_BONUS:
-      context.draw_surface(smalltux_sprite,
-          Vector(pos.x + offset.x, pos.y + offset.y - 10), LAYER_OBJECTS);
+    case NO_BONUS:
+      tux_sprite->set_action("small");
       break;
-    }
+    default:
+#ifdef DBEUG
+      std::cerr << "Bonus type not handled in worldmap.\n";
+#endif
+      tux_sprite->set_action("large");
+      break;
+  }
+
+  tux_sprite->draw(context, get_pos(), LAYER_OBJECTS);
 }
 
 
@@ -187,13 +191,23 @@ Tux::stop()
 void
 Tux::set_direction(Direction dir)
 {
-input_direction = dir;
+  input_direction = dir;
 }
 
 void
 Tux::action(float delta)
 {
-  if (!moving)
+  // check controller
+  if(main_controller->pressed(Controller::UP))
+    input_direction = D_NORTH;
+  else if(main_controller->pressed(Controller::DOWN))
+    input_direction = D_SOUTH;
+  else if(main_controller->pressed(Controller::LEFT))
+    input_direction = D_WEST;
+  else if(main_controller->pressed(Controller::RIGHT))
+    input_direction = D_EAST;
+
+  if(!moving)
     {
       if (input_direction != D_NONE)
         { 
@@ -220,8 +234,8 @@ Tux::action(float delta)
     }
   else
     {
-      // Let tux walk a few pixels (20 pixel/sec)
-      offset += 20.0f * delta;
+      // Let tux walk
+      offset += TUXSPEED * delta;
 
       if (offset > 32)
         { // We reached the next tile, so we check what to do now
@@ -345,10 +359,9 @@ WorldMap::WorldMap()
   messagedot   = new Surface(datadir +  "/images/worldmap/messagedot.png", true);
   teleporterdot   = new Surface(datadir +  "/images/worldmap/teleporterdot.png", true);
 
-  enter_level = false;
-
   name = "<no title>";
   music = "salcon.mod";
+  intro_displayed = false;
 
   total_stats.reset();
 }
@@ -368,11 +381,7 @@ WorldMap::~WorldMap()
 void
 WorldMap::load_map()
 {
-  std::string::size_type p = map_filename.find_last_of('/');
-  if(p == std::string::npos)                              
-    levels_path = "";
-  else
-    levels_path = map_filename.substr(0, p+1);
+  levels_path = FileSystem::dirname(map_filename);
 
   try {
     lisp::Parser parser;
@@ -397,6 +406,7 @@ WorldMap::load_map()
         const lisp::Lisp* props = iter.lisp();
         props->get("name", name);
         props->get("music", music);
+        props->get("intro-filename", intro_filename);
         props->get("start_pos_x", start_x);
         props->get("start_pos_y", start_y);
       } else if(iter.item() == "special-tiles") {
@@ -532,103 +542,33 @@ void
 WorldMap::on_escape_press()
 {
   // Show or hide the menu
-  if(!Menu::current())
-    {
-    Menu::set_current(worldmap_menu); 
+  if(!Menu::current()) {
+    Menu::set_current(worldmap_menu);
     tux->set_direction(D_NONE);  // stop tux movement when menu is called
-    }
-  else
-    Menu::set_current(0); 
+  } else {
+    Menu::set_current(0);
+  }
 }
 
 void
 WorldMap::get_input()
 {
-  enter_level = false;
-  SDLKey key;
+  main_controller->update();
 
   SDL_Event event;
-  while (SDL_PollEvent(&event))
-    {
-      if (Menu::current())
-        {
-          Menu::current()->event(event);
-        }
-      else
-        {
-          switch(event.type)
-            {
-            case SDL_QUIT:
-              Termination::abort("Received window close", "");
-              break;
-          
-            case SDL_KEYDOWN:
-              key = event.key.keysym.sym;
-
-              if(key == SDLK_ESCAPE)
-                on_escape_press();
-              else if(key == SDLK_RETURN || key == keymap.power)
-                enter_level = true;
-              else if(key == SDLK_LEFT || key == keymap.power)
-                tux->set_direction(D_WEST);
-              else if(key == SDLK_RIGHT || key == keymap.right)
-                tux->set_direction(D_EAST);
-              else if(key == SDLK_UP || key == keymap.up ||
-                key == keymap.jump)
-                  // there might be ppl that use jump as up key
-                tux->set_direction(D_NORTH);
-              else if(key == SDLK_DOWN || key == keymap.down)
-                tux->set_direction(D_SOUTH);
-              break;
-
-            case SDL_JOYHATMOTION:
-              if(event.jhat.value & SDL_HAT_UP) {
-                tux->set_direction(D_NORTH);
-              } else if(event.jhat.value & SDL_HAT_DOWN) {
-                tux->set_direction(D_SOUTH);
-              } else if(event.jhat.value & SDL_HAT_LEFT) {
-                tux->set_direction(D_WEST);
-              } else if(event.jhat.value & SDL_HAT_RIGHT) {
-                tux->set_direction(D_EAST);
-              }
-              break;
-          
-            case SDL_JOYAXISMOTION:
-              if (event.jaxis.axis == joystick_keymap.x_axis)
-                {
-                  if (event.jaxis.value < -joystick_keymap.dead_zone)
-                    tux->set_direction(D_WEST);
-                  else if (event.jaxis.value > joystick_keymap.dead_zone)
-                    tux->set_direction(D_EAST);
-                }
-              else if (event.jaxis.axis == joystick_keymap.y_axis)
-                {
-                  if (event.jaxis.value > joystick_keymap.dead_zone)
-                    tux->set_direction(D_SOUTH);
-                  else if (event.jaxis.value < -joystick_keymap.dead_zone)
-                    tux->set_direction(D_NORTH);
-                }
-              break;
-
-            case SDL_JOYBUTTONDOWN:
-              if (event.jbutton.button == joystick_keymap.b_button)
-                enter_level = true;
-              else if (event.jbutton.button == joystick_keymap.start_button)
-                on_escape_press();
-              break;
-
-            default:
-              break;
-            }
-        }
-    }
+  while (SDL_PollEvent(&event)) {
+    if (Menu::current())
+      Menu::current()->event(event);
+    main_controller->process_event(event);
+    if(event.type == SDL_QUIT)
+      throw std::runtime_error("Received window close");
+  }
 }
 
 Vector
 WorldMap::get_next_tile(Vector pos, Direction direction)
 {
-  switch(direction)
-    {
+  switch(direction) {
     case D_WEST:
       pos.x -= 1;
       break;
@@ -643,7 +583,7 @@ WorldMap::get_next_tile(Vector pos, Direction direction)
       break;
     case D_NONE:
       break;
-    }
+  }
   return pos;
 }
 
@@ -687,6 +627,35 @@ WorldMap::path_ok(Direction direction, Vector old_pos, Vector* new_pos)
 void
 WorldMap::update(float delta)
 {
+  Menu* menu = Menu::current();
+  if(menu) {
+    menu->action();
+
+    if(menu == worldmap_menu) {
+      switch (worldmap_menu->check())
+      {
+        case MNID_RETURNWORLDMAP: // Return to game  
+          Menu::set_current(0);
+          break;
+        case MNID_QUITWORLDMAP: // Quit Worldmap
+          quit = true;                               
+          break;
+      }
+    } else if(menu == options_menu) {
+      process_options_menu();
+    }
+
+    return;
+  }
+
+  bool enter_level = false;
+  if(main_controller->pressed(Controller::ACTION)
+      || main_controller->pressed(Controller::JUMP)
+      || main_controller->pressed(Controller::MENU_SELECT))
+    enter_level = true;
+  if(main_controller->pressed(Controller::PAUSE_MENU))
+    on_escape_press();
+  
   if (enter_level && !tux->is_moving())
     {
       /* Check special tile action */
@@ -696,7 +665,7 @@ WorldMap::update(float delta)
         if (special_tile->teleport_dest != Vector(-1,-1))
           {
           // TODO: an animation, camera scrolling or a fading would be a nice touch
-          SoundManager::get()->play_sound(IDToSound(SND_WARP));
+          sound_manager->play_sound("warp");
           tux->back_direction = D_NONE;
           tux->set_tile_pos(special_tile->teleport_dest);
           SDL_Delay(1000);
@@ -719,7 +688,6 @@ WorldMap::update(float delta)
         {
           PlayerStatus old_player_status = player_status;
 
-          std::cout << "Enter the current level: " << level->name << std::endl;
           // do a shriking fade to the level
           shrink_fade(Vector((level->pos.x*32 + 16 + offset.x),
                              (level->pos.y*32 + 16 + offset.y)), 500);
@@ -738,14 +706,6 @@ WorldMap::update(float delta)
                 level->statistics.merge(global_stats);
                 calculate_total_stats();
 
-                if (session.get_current_sector()->player->got_power !=
-                      session.get_current_sector()->player->NONE_POWER)
-                  player_status.bonus = PlayerStatus::FLOWER_BONUS;
-                else if (session.get_current_sector()->player->size == BIG)
-                  player_status.bonus = PlayerStatus::GROWUP_BONUS;
-                else
-                  player_status.bonus = PlayerStatus::NO_BONUS;
-
                 if (old_level_state != level->solved && level->auto_path)
                   { // Try to detect the next direction to which we should walk
                     // FIXME: Mostly a hack
@@ -771,8 +731,6 @@ WorldMap::update(float delta)
                         tux->set_direction(dir);
                         //tux->update(delta);
                       }
-
-                    std::cout << "Walk to dir: " << dir << std::endl;
                   }
               }
 
@@ -781,9 +739,9 @@ WorldMap::update(float delta)
               level_finished = false;
               /* In case the player's abort the level, keep it using the old
                   status. But the minimum lives and no bonus. */
-              player_status.distros = old_player_status.distros;
+              player_status.coins = old_player_status.coins;
               player_status.lives = std::min(old_player_status.lives, player_status.lives);
-              player_status.bonus = player_status.NO_BONUS;
+              player_status.bonus = NO_BONUS;
 
               break;
             case GameSession::ES_GAME_OVER:
@@ -800,19 +758,18 @@ WorldMap::update(float delta)
                   LAYER_BACKGROUND0);
 
               context.draw_text(blue_text, _("GAMEOVER"), 
-                  Vector(screen->w/2, 200), CENTER_ALLIGN, LAYER_FOREGROUND1);
+                  Vector(SCREEN_WIDTH/2, 200), CENTER_ALLIGN, LAYER_FOREGROUND1);
 
-              sprintf(str, _("COINS: %d"), player_status.distros);
+              sprintf(str, _("COINS: %d"), player_status.coins);
               context.draw_text(gold_text, str,
-                  Vector(screen->w/2, screen->w - 32), CENTER_ALLIGN,
+                  Vector(SCREEN_WIDTH/2, SCREEN_WIDTH - 32), CENTER_ALLIGN,
                   LAYER_FOREGROUND1);
 
               total_stats.draw_message_info(context, _("Total Statistics"));
 
               context.do_drawing();
 
-              SDL_Event event;
-              wait_for_event(event,2000,6000,true);
+              wait_for_event(2.0, 6.0);
 
               quit = true;
               player_status.reset();
@@ -824,21 +781,19 @@ WorldMap::update(float delta)
               break;
             }
 
-          SoundManager::get()->play_music(song);
+          sound_manager->play_music(song);
           Menu::set_current(0);
           if (!savegame_file.empty())
             savegame(savegame_file);
         }
       /* The porpose of the next checking is that if the player lost
          the level (in case there is one), don't show anything */
-      if(level_finished)
-        {
-        if (!level->extro_filename.empty())
-          {
+      if(level_finished) {
+        if (!level->extro_filename.empty()) {
           // Display a text file
-          display_text_file(level->extro_filename, SCROLL_SPEED_MESSAGE,
-              white_big_text , white_text, white_small_text, blue_text );
-          }
+          std::string filename = levels_path + level->extro_filename;
+          display_text_file(filename);
+        }
 
         if (!level->next_worldmap.empty())
           {
@@ -854,28 +809,6 @@ WorldMap::update(float delta)
       tux->action(delta);
 //      tux->set_direction(input_direction);
     }
-  
-  Menu* menu = Menu::current();
-  if(menu)
-    {
-      menu->action();
-
-      if(menu == worldmap_menu)
-        {
-          switch (worldmap_menu->check())
-            {
-            case MNID_RETURNWORLDMAP: // Return to game
-              break;
-            case MNID_QUITWORLDMAP: // Quit Worldmap
-              quit = true;
-              break;
-            }
-        }
-      else if(menu == options_menu)
-        {
-          process_options_menu();
-        }
-    }
 }
 
 const Tile*
@@ -915,26 +848,24 @@ WorldMap::at_special_tile()
   return 0;
 }
 
-
 void
-WorldMap::draw(DrawingContext& context, const Vector& offset)
+WorldMap::draw(DrawingContext& context)
 {
   for(int y = 0; y < height; ++y)
     for(int x = 0; x < width; ++x)
       {
         const Tile* tile = at(Vector(x, y));
-        tile->draw(context, Vector(x*32 + offset.x, y*32 + offset.y),
-            LAYER_TILES);
+        tile->draw(context, Vector(x*32, y*32), LAYER_TILES);
       }
 
   for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
     {
       if (i->solved)
         context.draw_surface(leveldot_green,
-            Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1);
+            Vector(i->pos.x*32, i->pos.y*32), LAYER_TILES+1);
       else
         context.draw_surface(leveldot_red,
-            Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1);
+            Vector(i->pos.x*32, i->pos.y*32), LAYER_TILES+1);
     }
 
   for(SpecialTiles::iterator i = special_tiles.begin(); i != special_tiles.end(); ++i)
@@ -944,50 +875,53 @@ WorldMap::draw(DrawingContext& context, const Vector& offset)
 
       if (i->teleport_dest != Vector(-1, -1))
         context.draw_surface(teleporterdot,
-                Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1);
+                Vector(i->pos.x*32, i->pos.y*32), LAYER_TILES+1);
 
       else if (!i->map_message.empty() && !i->passive_message)
         context.draw_surface(messagedot,
-                Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1);
+                Vector(i->pos.x*32, i->pos.y*32), LAYER_TILES+1);
     }
 
-  tux->draw(context, offset);
+  tux->draw(context);
   draw_status(context);
 }
 
 void
 WorldMap::draw_status(DrawingContext& context)
 {
+  context.push_transform();
+  context.set_translation(Vector(0, 0));
+  
   char str[80];
   sprintf(str, " %d", total_stats.get_points(SCORE_STAT));
 
   context.draw_text(white_text, _("SCORE"), Vector(0, 0), LEFT_ALLIGN, LAYER_FOREGROUND1);
   context.draw_text(gold_text, str, Vector(96, 0), LEFT_ALLIGN, LAYER_FOREGROUND1);
 
-  sprintf(str, "%d", player_status.distros);
-  context.draw_text(white_text, _("COINS"), Vector(screen->w/2 - 16*5, 0),
+  sprintf(str, "%d", player_status.coins);
+  context.draw_text(white_text, _("COINS"), Vector(SCREEN_WIDTH/2 - 16*5, 0),
       LEFT_ALLIGN, LAYER_FOREGROUND1);
-  context.draw_text(gold_text, str, Vector(screen->w/2 + (16*5)/2, 0),
+  context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2 + (16*5)/2, 0),
         LEFT_ALLIGN, LAYER_FOREGROUND1);
 
   if (player_status.lives >= 5)
     {
       sprintf(str, "%dx", player_status.lives);
       context.draw_text(gold_text, str, 
-          Vector(screen->w - gold_text->get_text_width(str) - tux_life->w, 0),
+          Vector(SCREEN_WIDTH - gold_text->get_text_width(str) - tux_life->w, 0),
           LEFT_ALLIGN, LAYER_FOREGROUND1);
-      context.draw_surface(tux_life, Vector(screen->w -
+      context.draw_surface(tux_life, Vector(SCREEN_WIDTH -
             gold_text->get_text_width("9"), 0), LEFT_ALLIGN, LAYER_FOREGROUND1);
     }
   else
     {
       for(int i= 0; i < player_status.lives; ++i)
         context.draw_surface(tux_life,
-            Vector(screen->w - tux_life->w*4 + (tux_life->w*i), 0),
+            Vector(SCREEN_WIDTH - tux_life->w*4 + (tux_life->w*i), 0),
             LAYER_FOREGROUND1);
     }
   context.draw_text(white_text, _("LIVES"),
-      Vector(screen->w - white_text->get_text_width(_("LIVES")) - white_text->get_text_width("   99"), 0),
+      Vector(SCREEN_WIDTH - white_text->get_text_width(_("LIVES")) - white_text->get_text_width("   99"), 0),
       LEFT_ALLIGN, LAYER_FOREGROUND1);
 
   if (!tux->is_moving())
@@ -1000,8 +934,8 @@ WorldMap::draw_status(DrawingContext& context)
                 get_level_title(*i);
 
               context.draw_text(white_text, i->title, 
-                  Vector(screen->w/2,
-                         screen->h - white_text->get_height() - 30),
+                  Vector(SCREEN_WIDTH/2,
+                         SCREEN_HEIGHT - white_text->get_height() - 30),
                   CENTER_ALLIGN, LAYER_FOREGROUND1);
 
               i->statistics.draw_worldmap_info(context);
@@ -1015,8 +949,8 @@ WorldMap::draw_status(DrawingContext& context)
                /* Display an in-map message in the map, if any as been selected */
               if(!i->map_message.empty() && !i->passive_message)
                 context.draw_text(gold_text, i->map_message, 
-                    Vector(screen->w/2,
-                           screen->h - white_text->get_height() - 60),
+                    Vector(SCREEN_WIDTH/2,
+                           SCREEN_HEIGHT - white_text->get_height() - 60),
                     CENTER_ALLIGN, LAYER_FOREGROUND1);
               break;
             }
@@ -1025,8 +959,10 @@ WorldMap::draw_status(DrawingContext& context)
   /* Display a passive message in the map, if needed */
   if(passive_message_timer.check())
     context.draw_text(gold_text, passive_message, 
-            Vector(screen->w/2, screen->h - white_text->get_height() - 60),
+            Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT - white_text->get_height() - 60),
             CENTER_ALLIGN, LAYER_FOREGROUND1);
+
+  context.pop_transform();
 }
 
 void
@@ -1036,53 +972,52 @@ WorldMap::display()
 
   quit = false;
 
-  song = SoundManager::get()->load_music(datadir +  "/music/" + music);
-  SoundManager::get()->play_music(song);
-
-  FrameRate frame_rate(10);
-  frame_rate.set_frame_limit(false);
+  song = sound_manager->load_music(datadir +  "/music/" + music);
+  sound_manager->play_music(song);
 
-  frame_rate.start();
+  if(!intro_displayed && intro_filename != "") {
+    std::string filename = levels_path + intro_filename;
+    display_text_file(filename);
+    intro_displayed = true;
+  }
 
+  Uint32 lastticks = SDL_GetTicks();
   DrawingContext context;
-  while(!quit)
-    {
-      float delta = frame_rate.get();
-
-      delta *= 1.3f;
-
-      if (delta > 10.0f)
-        delta = .3f;
-       
-      frame_rate.update();
-
-      Vector tux_pos = tux->get_pos();
-      if (1)
-        {
-          offset.x = -tux_pos.x + screen->w/2;
-          offset.y = -tux_pos.y + screen->h/2;
-
-          if (offset.x > 0) offset.x = 0;
-          if (offset.y > 0) offset.y = 0;
+  while(!quit) {
+    Uint32 ticks = SDL_GetTicks();
+    float elapsed_time = float(ticks - lastticks) / 1000;
+    global_time += elapsed_time;
+    lastticks = ticks;
+    
+    // 40 fps minimum
+    if(elapsed_time > .025)
+      elapsed_time = .025;
+    
+    Vector tux_pos = tux->get_pos();
+    
+    offset.x = -tux_pos.x + SCREEN_WIDTH/2;
+    offset.y = -tux_pos.y + SCREEN_HEIGHT/2;
 
-          if (offset.x < screen->w - width*32) offset.x = screen->w - width*32;
-          if (offset.y < screen->h - height*32) offset.y = screen->h - height*32;
-        } 
+    if (offset.x > 0) offset.x = 0;
+    if (offset.y > 0) offset.y = 0;
 
-      draw(context, offset);
-      get_input();
-      update(delta);
+    if (offset.x < SCREEN_WIDTH - width*32) offset.x = SCREEN_WIDTH - width*32;
+    if (offset.y < SCREEN_HEIGHT - height*32) offset.y = SCREEN_HEIGHT - height*32;
+  
+    context.push_transform();
+    context.set_translation(-offset);
+    draw(context);
+    context.pop_transform();
+    get_input();
+    update(elapsed_time);
       
-      if(Menu::current())
-        {
-          Menu::current()->draw(context);
-          mouse_cursor->draw(context);
-        }
-
-      context.do_drawing();
-
-      SDL_Delay(20);
+    if(Menu::current()) {
+      Menu::current()->draw(context);
+      mouse_cursor->draw(context);
     }
+
+    context.do_drawing();
+  }
 }
 
 void
@@ -1091,8 +1026,6 @@ WorldMap::savegame(const std::string& filename)
   if(filename == "")
     return;
 
-  std::cout << "savegame: " << filename << std::endl;
-
   std::ofstream file(filename.c_str(), std::ios::out);
   lisp::Writer writer(file);
 
@@ -1114,16 +1047,15 @@ WorldMap::savegame(const std::string& filename)
   writer.write_string("title",
       std::string(name + " - " + nb_solved_levels_str+"/"+total_levels_str));
   writer.write_string("map", map_filename);
-  writer.write_int("lives", player_status.lives);
-  writer.write_int("distros", player_status.lives);
-  writer.write_int("max-score-multiplier", player_status.max_score_multiplier);
+  writer.write_bool("intro-displayed", intro_displayed);
 
   writer.start_list("tux");
 
   writer.write_float("x", tux->get_tile_pos().x);
   writer.write_float("y", tux->get_tile_pos().y);
   writer.write_string("back", direction_to_string(tux->back_direction));
-  writer.write_string("bonus", bonus_to_string(player_status.bonus));
+  player_status.write(writer);
+  writer.write_string("back", direction_to_string(tux->back_direction));
 
   writer.end_list("tux");
 
@@ -1167,25 +1099,24 @@ WorldMap::loadgame(const std::string& filename)
     savegame->get("map", map_filename);
     load_map(); 
 
+    savegame->get("intro-displayed", intro_displayed);
     savegame->get("lives", player_status.lives);
-    savegame->get("distros", player_status.distros);
+    savegame->get("coins", player_status.coins);
     savegame->get("max-score-multiplier", player_status.max_score_multiplier);
     if (player_status.lives < 0)
-      player_status.lives = START_LIVES;
+      player_status.reset();
 
     const lisp::Lisp* tux_lisp = savegame->get_lisp("tux");
     if(tux)
     {
       Vector p;
       std::string back_str = "none";
-      std::string bonus_str = "none";
 
       tux_lisp->get("x", p.x);
       tux_lisp->get("y", p.y);
       tux_lisp->get("back", back_str);
-      tux_lisp->get("bonus", bonus_str);
+      player_status.read(*tux_lisp);
       
-      player_status.bonus = string_to_bonus(bonus_str);
       tux->back_direction = string_to_direction(back_str);      
       tux->set_tile_pos(p);
     }
@@ -1236,8 +1167,3 @@ WorldMap::loadmap(const std::string& filename)
 }
 
 } // namespace WorldMapNS
-
-/* Local Variables: */
-/* mode:c++ */
-/* End: */
-