Pause music when pressing ESC during a level and resume it when exiting the pause...
[supertux.git] / src / object / tilemap.hpp
index ff6bd0b..17e151c 100644 (file)
@@ -34,7 +34,7 @@ class TileSet;
 /**
  * This class is responsible for drawing the level tiles
  */
-class TileMap : public GameObject, 
+class TileMap : public GameObject,
                 public ScriptInterface
 {
 public:
@@ -76,16 +76,26 @@ public:
   Vector get_offset() const
   { return offset; }
 
-  const Vector& get_movement() const
+  /** Get the movement of this tilemap. The collision detection code may need a
+   *  non-negative y-movement. Passing `false' as the `actual' argument will
+   *  provide that. Used exclusively in src/supertux/sector.cpp. */
+  Vector get_movement(bool actual) const
   {
-    return movement;
+    if(actual) {
+      return movement;
+    } else {
+      return Vector(movement.x, std::max(0.0f,movement.y));
+    }
   }
 
-  Path *get_path()
-  { return path.get(); }
+  std::shared_ptr<Path> get_path()
+  { return path; }
 
-  void set_offset(const Vector &offset)
-  { this->offset = offset; }
+  std::shared_ptr<PathWalker> get_walker()
+  { return walker; }
+
+  void set_offset(const Vector &offset_)
+  { this->offset = offset_; }
 
   /* Returns the position of the upper-left corner of
    * tile (x, y) in the sector. */
@@ -106,7 +116,7 @@ public:
   { return z_pos; }
 
   bool is_solid() const
-  { return solid; }
+  { return real_solid && effective_solid; }
 
   /**
    * Changes Tilemap's solidity, i.e. whether to consider it when doing collision detection.
@@ -161,7 +171,14 @@ private:
   typedef std::vector<uint32_t> Tiles;
   Tiles tiles;
 
-  bool solid;
+  /* read solid: In *general*, is this a solid layer?
+   * effective solid: is the layer *currently* solid? A generally solid layer
+   * may be not solid when its alpha is low.
+   * See `is_solid' above. */
+  bool real_solid;
+  bool effective_solid;
+  void update_effective_solid (void);
+
   float speed_x;
   float speed_y;
   int width, height;
@@ -174,8 +191,8 @@ private:
   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;
+  std::shared_ptr<Path> path;
+  std::shared_ptr<PathWalker> walker;
 
   DrawingContext::Target draw_target; /**< set to LIGHTMAP to draw to lightmap */