From: Tobias Markus Date: Mon, 6 Oct 2014 22:19:25 +0000 (+0200) Subject: More robust way of calculating the falling layer X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=16d8d6d0583146730d2213ff6494c5e59add7b43;p=supertux.git More robust way of calculating the falling layer --- diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 0b397c95e..8b85567ab 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -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(); diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index 2a7dc37e2..b5c75807e 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -108,6 +108,8 @@ Sector::Sector(Level* parent) : throw scripting::SquirrelError(global_vm, "Couldn't get sector table"); sq_addref(global_vm, §or_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(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) { diff --git a/src/supertux/sector.hpp b/src/supertux/sector.hpp index 4388c857f..b28d82692 100644 --- a/src/supertux/sector.hpp +++ b/src/supertux/sector.hpp @@ -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;