TileMaps can now use paths
[supertux.git] / src / object / tilemap.hpp
index 3210bde..20969bd 100644 (file)
 
 #include <vector>
 #include <stdint.h>
+#include <string>
 
 #include "game_object.hpp"
 #include "serializable.hpp"
 #include "math/vector.hpp"
 #include "video/drawing_context.hpp"
+#include "object/path.hpp"
+#include "object/path_walker.hpp"
+#include "script_interface.hpp"
 
 namespace lisp {
 class Lisp;
@@ -39,12 +43,12 @@ class Tile;
 /**
  * This class is reponsible for drawing the level tiles
  */
-class TileMap : public GameObject, public Serializable
+class TileMap : public GameObject, public Serializable, public ScriptInterface
 {
 public:
   TileMap();
   TileMap(const lisp::Lisp& reader, TileManager* tile_manager = 0);
-  TileMap(int layer_, bool solid_, size_t width_, size_t height_);
+  TileMap(std::string name, int z_pos, bool solid_, size_t width_, size_t height_);
   virtual ~TileMap();
 
   virtual void write(lisp::Writer& writer);
@@ -52,8 +56,20 @@ public:
   virtual void update(float elapsed_time);
   virtual void draw(DrawingContext& context);
 
+  /** Move tilemap until at given node, then stop */
+  void goto_node(int node_no);
+
+  /** Start moving tilemap */
+  void start_moving();
+
+  /** Stop tilemap at next node */
+  void stop_moving();
+  
+  virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
+  virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
+
   void set(int width, int height, const std::vector<unsigned int>& vec,
-      int layer, bool solid);
+      int z_pos, bool solid);
 
   /** resizes the tilemap to a new width and height (tries to not destroy the
    * existing map)
@@ -66,9 +82,21 @@ public:
   size_t get_height() const
   { return height; }
 
+  float get_x_offset() const
+  { return x_offset; }
+
+  float get_y_offset() const
+  { return y_offset; }
+
+  void set_x_offset(float x_offset)
+  { this->x_offset = x_offset; }
+
+  void set_y_offset(float y_offset)
+  { this->y_offset = y_offset; }
+
   int get_layer() const
-  { return layer; }
-  
+  { return z_pos; }
+
   bool is_solid() const
   { return solid; }
 
@@ -99,19 +127,32 @@ public:
     return drawing_effect;
   }
 
+  /**
+   * Start fading the tilemap to opacity given by @c alpha.
+   * Destination opacity will be reached after @c seconds seconds.
+   */
+  void fade(float alpha, float seconds = 0);
+
 private:
   typedef std::vector<uint32_t> Tiles;
   Tiles tiles;
-  
+
 private:
   TileManager* tilemanager;
   bool solid;
   float speed;
   int width, height;
-  int layer;
+  int z_pos;
+  float x_offset;
+  float y_offset;
 
   DrawingEffect drawing_effect;
+  float alpha; /**< requested tilemap opacity */
+  float current_alpha; /**< current tilemap opacity */
+  float remaining_fade_time; /**< seconds until requested tilemap opacity is reached */
+  
+  std::auto_ptr<Path> path;
+  std::auto_ptr<PathWalker> walker;
 };
 
 #endif /*SUPERTUX_TILEMAP_H*/
-