- made fixes to buttjump
[supertux.git] / src / worldmap.cpp
index 366deb5..990fce2 100644 (file)
@@ -420,6 +420,7 @@ WorldMap::load_map()
                       level.south = true;
                       level.west  = true;
 
+                      reader.read_string("extro-filename",  &level.extro_filename);
                       reader.read_string("name",  &level.name);
                       reader.read_int("x", &level.x);
                       reader.read_int("y", &level.y);
@@ -626,7 +627,7 @@ WorldMap::path_ok(Direction direction, Point old_pos, Point* new_pos)
 }
 
 void
-WorldMap::update()
+WorldMap::update(float delta)
 {
   if (enter_level && !tux->is_moving())
     {
@@ -673,11 +674,24 @@ WorldMap::update()
                         if (dir != NONE)
                           {
                             tux->set_direction(dir);
-                            tux->update(0.33f);
+                            //tux->update(delta);
                           }
 
                         std::cout << "Walk to dir: " << dir << std::endl;
                       }
+
+                    if (!level->extro_filename.empty())
+                      { 
+                        MusicRef theme =
+                          music_manager->load_music(datadir + "/music/theme.mod");
+                        music_manager->play_music(theme);
+                        // Display final credits and go back to the main menu
+                        display_text_file(level->extro_filename,
+                                          "/images/background/extro.jpg", SCROLL_SPEED_MESSAGE);
+                        display_text_file("CREDITS",
+                                          "/images/background/oiltux.jpg", SCROLL_SPEED_CREDITS);
+                        quit = true;
+                      }
                   }
 
                   break;
@@ -692,7 +706,7 @@ WorldMap::update()
                   break;
                 case GameSession::GAME_OVER:
                   quit = true;
-                  player_status.bonus = PlayerStatus::NO_BONUS;
+                  player_status.reset();
                   break;
                 case GameSession::NONE:
                   // Should never be reached 
@@ -714,8 +728,8 @@ WorldMap::update()
     }
   else
     {
+      tux->update(delta);
       tux->set_direction(input_direction);
-      tux->update(0.33f);
     }
   
   Menu* menu = Menu::current();
@@ -729,11 +743,6 @@ WorldMap::update()
             {
             case MNID_RETURNWORLDMAP: // Return to game
               break;
-            case MNID_SAVEGAME:
-              if (!savegame_file.empty())
-                savegame(savegame_file);
-              break;
-                
             case MNID_QUITWORLDMAP: // Quit Worldmap
               quit = true;
               break;
@@ -812,7 +821,7 @@ WorldMap::draw_status()
   if (player_status.lives >= 5)
     {
       sprintf(str, "%dx", player_status.lives);
-      gold_text->draw(str, 585, 0);
+      gold_text->draw_align(str, 617, 0, A_RIGHT, A_TOP);
       tux_life->draw(565+(18*3), 0);
     }
   else
@@ -845,33 +854,49 @@ WorldMap::display()
   song = music_manager->load_music(datadir +  "/music/" + music);
   music_manager->play_music(song);
 
-  while(!quit) {
-    Point tux_pos = tux->get_pos();
-    if (1)
-      {
-        offset.x = -tux_pos.x + screen->w/2;
-        offset.y = -tux_pos.y + screen->h/2;
+  unsigned int last_update_time;
+  unsigned int update_time;
 
-        if (offset.x > 0) offset.x = 0;
-        if (offset.y > 0) offset.y = 0;
+  last_update_time = update_time = st_get_ticks();
 
-        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;
-      } 
+  while(!quit)
+    {
+      float delta = ((float)(update_time-last_update_time))/100.0;
 
-    draw(offset);
-    get_input();
-    update();
+      delta *= 1.3f;
 
-  if(Menu::current())
-    {
-      Menu::current()->draw();
-      mouse_cursor->draw();
-    }
-    flipscreen();
+      if (delta > 10.0f)
+        delta = .3f;
+      
+      last_update_time = update_time;
+      update_time      = st_get_ticks();
 
-    SDL_Delay(20);
-  }
+      Point 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;
+
+          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;
+        } 
+
+      draw(offset);
+      get_input();
+      update(delta);
+
+      if(Menu::current())
+        {
+          Menu::current()->draw();
+          mouse_cursor->draw();
+        }
+      flipscreen();
+
+      SDL_Delay(20);
+    }
 }
 
 void
@@ -921,6 +946,12 @@ WorldMap::loadgame(const std::string& filename)
     return;
   
   lisp_object_t* savegame = lisp_read_from_file(filename);
+  if (!savegame)
+    {
+      std::cout << "WorldMap:loadgame: File not found: " << filename << std::endl;
+      return;
+    }
+
   lisp_object_t* cur = savegame;
 
   if (strcmp(lisp_symbol(lisp_car(cur)), "supertux-savegame") != 0)