Skip to content

Commit

Permalink
Split get_foremost_layer and get_foremost_opaque_layer
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbi committed Jan 24, 2024
1 parent 651caaa commit f62ddbc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/badguy/badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ BadGuy::kill_fall()

// Set the badguy layer to be the foremost, so that
// this does not reveal secret tilemaps:
m_layer = Sector::get().get_foremost_layer() + 1;
m_layer = Sector::get().get_foremost_opaque_layer() + 1;
// Start the dead-script.
run_dead_script();
}
Expand Down
4 changes: 2 additions & 2 deletions src/badguy/yeti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void Yeti::take_hit(Player& )

// Set the badguy layer to be above the foremost, so that
// this does not reveal secret tilemaps:
m_layer = Sector::get().get_foremost_layer() + 1;
m_layer = Sector::get().get_foremost_opaque_layer() + 1;
m_state = SQUISHED;
m_state_timer.start(YETI_SQUISH_TIME);
set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC);
Expand Down Expand Up @@ -394,7 +394,7 @@ Yeti::SnowExplosionParticle::SnowExplosionParticle(const Vector& pos, const Vect
m_physic.set_velocity(velocity);
m_physic.enable_gravity(true);
set_state(STATE_FALLING);
m_layer = Sector::get().get_foremost_layer() + 1;
m_layer = Sector::get().get_foremost_opaque_layer() + 1;
}

std::vector<Direction>
Expand Down
2 changes: 1 addition & 1 deletion src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,7 @@ Player::draw(DrawingContext& context)
} // don't draw Tux

else if (m_dying)
m_sprite->draw(context.color(), get_pos(), Sector::get().get_foremost_layer() + 1);
m_sprite->draw(context.color(), get_pos(), Sector::get().get_foremost_opaque_layer() + 1);
else
m_sprite->draw(context.color(), get_pos(), LAYER_OBJECTS + 1);

Expand Down
14 changes: 11 additions & 3 deletions src/supertux/sector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Sector::Sector(Level& parent) :
m_level(parent),
m_fully_constructed(false),
m_foremost_layer(),
m_foremost_opaque_layer(),
m_gravity(10.0f),
m_collision_system(new CollisionSystem(*this)),
m_text_object(add<TextObject>("Text"))
Expand Down Expand Up @@ -154,7 +155,8 @@ Sector::finish_construction(bool editable)
m_initialized = false;
flush_game_objects();

m_foremost_layer = calculate_foremost_layer();
m_foremost_layer = calculate_foremost_layer(false);
m_foremost_opaque_layer = calculate_foremost_layer();

process_resolve_requests();

Expand Down Expand Up @@ -302,14 +304,14 @@ Sector::get_active_region() const
}

int
Sector::calculate_foremost_layer() const
Sector::calculate_foremost_layer(bool including_transparent) const
{
int layer = LAYER_BACKGROUND0;
for (auto& tm : get_objects_by_type<TileMap>())
{
if (tm.get_layer() > layer)
{
if ( (tm.get_alpha() < 1.0f) )
if ( including_transparent && tm.get_alpha() < 1.0f )
{
layer = tm.get_layer() - 1;
}
Expand All @@ -323,6 +325,12 @@ Sector::calculate_foremost_layer() const
return layer;
}

int
Sector::get_foremost_opaque_layer() const
{
return m_foremost_opaque_layer;
}

int
Sector::get_foremost_layer() const
{
Expand Down
4 changes: 3 additions & 1 deletion src/supertux/sector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class Sector final : public Base::Sector

Rectf get_active_region() const;

int get_foremost_opaque_layer() const;
int get_foremost_layer() const;

/** returns the editor size (in tiles) of a sector */
Expand All @@ -156,7 +157,7 @@ class Sector final : public Base::Sector
virtual bool before_object_add(GameObject& object) override;
virtual void before_object_remove(GameObject& object) override;

int calculate_foremost_layer() const;
int calculate_foremost_layer(bool including_transparent = true) const;

/** Convert tiles into their corresponding GameObjects (e.g.
bonusblocks, add light to lava tiles) */
Expand All @@ -167,6 +168,7 @@ class Sector final : public Base::Sector

bool m_fully_constructed;
int m_foremost_layer;
int m_foremost_opaque_layer;

float m_gravity;

Expand Down

0 comments on commit f62ddbc

Please sign in to comment.