More robust way of calculating the falling layer
authorTobias Markus <tobbi@mozilla-uk.org>
Mon, 6 Oct 2014 22:19:25 +0000 (00:19 +0200)
committerTobias Markus <tobbi@mozilla-uk.org>
Mon, 6 Oct 2014 22:19:25 +0000 (00:19 +0200)
src/badguy/badguy.cpp
src/supertux/sector.cpp
src/supertux/sector.hpp

index 0b397c9..8b85567 100644 (file)
@@ -31,7 +31,6 @@ static const float SQUISH_TIME = 2;
 
 static const float X_OFFSCREEN_DISTANCE = 1280;
 static const float Y_OFFSCREEN_DISTANCE = 800;
-static const int LAYER_FALLING = 500;
 
 BadGuy::BadGuy(const Vector& pos, const std::string& sprite_name_, int layer_) :
   MovingSprite(pos, sprite_name_, layer_, COLGROUP_DISABLED),
@@ -411,7 +410,10 @@ BadGuy::kill_fall()
   physic.set_acceleration_y(0);
   physic.enable_gravity(true);
   set_state(STATE_FALLING);
-  layer = LAYER_FALLING;
+
+  // Set the badguy layer to be the foremost, so that
+  // this does not reveal secret tilemaps:
+  layer = Sector::current()->get_foremost_layer() + 1;
 
   // start dead-script
   run_dead_script();
index 2a7dc37..b5c7580 100644 (file)
@@ -108,6 +108,8 @@ Sector::Sector(Level* parent) :
     throw scripting::SquirrelError(global_vm, "Couldn't get sector table");
   sq_addref(global_vm, &sector_table);
   sq_pop(global_vm, 1);
+
+  foremost_layer = calculate_foremost_layer();
 }
 
 Sector::~Sector()
@@ -650,6 +652,28 @@ Sector::get_active_region()
     camera->get_translation() + Vector(1600, 1200) + Vector(SCREEN_WIDTH,SCREEN_HEIGHT));
 }
 
+int
+Sector::calculate_foremost_layer()
+{
+  int layer = 0;
+  for(auto i = gameobjects.begin(); i != gameobjects.end(); ++i)
+  {
+    TileMap* tm = dynamic_cast<TileMap*>(i->get());
+    if (!tm) continue;
+    if(tm->get_layer() > foremost_layer)
+    {
+      foremost_layer = tm->get_layer();
+    }
+  }
+  return layer;
+}
+
+int
+Sector::get_foremost_layer()
+{
+  return foremost_layer;
+}
+
 void
 Sector::update(float elapsed_time)
 {
index 4388c85..b28d826 100644 (file)
@@ -170,6 +170,8 @@ public:
 
   Rectf get_active_region();
 
+  int get_foremost_layer();
+
   /**
    * returns the width (in px) of a sector)
    */
@@ -245,6 +247,8 @@ private:
 
   void fix_old_tiles();
 
+  int calculate_foremost_layer();
+
 private:
   static Sector* _current;
 
@@ -268,6 +272,8 @@ private:
 
   Color ambient_light;
 
+  int foremost_layer;
+
 public: // TODO make this private again
   /// show collision rectangles of moving objects (for debugging)
   static bool show_collrects;