Issue #89: Respawn Tux at original, not current position. This is because upon restar...
[supertux.git] / src / worldmap / level.cpp
index c4fc951..aafa660 100644 (file)
@@ -1,4 +1,4 @@
-//  $Id: worldmap.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
+//  $Id$
 //
 //  SuperTux
 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <config.h>
 
+#include <stddef.h>
 #include <physfs.h>
-#include "level.hpp"
+#include "worldmap/level.hpp"
 #include "sprite/sprite_manager.hpp"
 #include "sprite/sprite.hpp"
 #include "video/drawing_context.hpp"
+#include "log.hpp"
+#include "file_system.hpp"
 
 namespace WorldMapNS
 {
 
-Level::Level(const std::string& basedir, const lisp::Lisp* lisp)
-  : solved(false), auto_path(true)
+LevelTile::LevelTile(const std::string& basedir, const lisp::Lisp* lisp)
+  : solved(false), auto_play(false), auto_path(true), basedir(basedir), picture_cached(false),
+    picture(0)
 {
+  lisp->get("name", name);
   lisp->get("x", pos.x);
   lisp->get("y", pos.y);
-  
+  lisp->get("auto-play", auto_play);
+
   std::string spritefile = "images/worldmap/common/leveldot.sprite";
   lisp->get("sprite", spritefile);
   sprite.reset(sprite_manager->create(spritefile));
 
   lisp->get("extro-script", extro_script);
-  lisp->get("name", name);
-  
+
   if (!PHYSFS_exists((basedir + name).c_str()))
   {
-    log_warning << "level file '" << name 
+    log_warning << "level file '" << name
       << "' does not exist and will not be added to the worldmap" << std::endl;
     return;
   }
 }
 
-Level::~Level()
+LevelTile::~LevelTile()
 {
+  delete picture;
 }
 
 void
-Level::draw(DrawingContext& context)
+LevelTile::draw(DrawingContext& context)
 {
   sprite->draw(context, pos*32 + Vector(16, 16), LAYER_OBJECTS - 1);
 }
 
 void
-Level::update(float )
+LevelTile::update(float )
 {
 }
 
+const Surface*
+LevelTile::get_picture()
+{
+  if (picture_cached) return picture;
+  picture_cached = true;
+  std::string fname = FileSystem::strip_extension(basedir + name)+".jpg";
+  if (!PHYSFS_exists(fname.c_str())) {
+       return 0;
+  }
+  picture = new Surface(fname);
+  return picture;
+}
+
 }