Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions src/badguy/granito.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "badguy/granito_big.hpp"
#include "math/random.hpp"
#include "object/rock.hpp"
#include "object/player.hpp"
#include "supertux/sector.hpp"
#include "util/reader_mapping.hpp"
Expand All @@ -28,7 +29,7 @@ Granito::Granito(const ReaderMapping& reader, const std::string& sprite_name, in
m_state(STATE_STAND),
m_original_state(STATE_STAND),
m_has_waved(false),
m_stepped_on(false),
m_has_entity_on_top(false),
m_airborne(false),
m_detect_script(),
m_carried_script()
Expand All @@ -54,7 +55,7 @@ Granito::active_update(float dt_sec)
{
// Don't do any extra calculations
WalkingBadguy::active_update(dt_sec);
m_stepped_on = false;
m_has_entity_on_top = false;
return;
}

Expand Down Expand Up @@ -88,11 +89,11 @@ Granito::active_update(float dt_sec)
{
// Don't do any extra calculations
WalkingBadguy::active_update(dt_sec);
m_stepped_on = false;
m_has_entity_on_top = false;
return;
}

if ((m_state == STATE_LOOKUP && !m_stepped_on) ||
if ((m_state == STATE_LOOKUP && !m_has_entity_on_top) ||
(m_state == STATE_JUMPING && on_ground()))
{
restore_original_state();
Expand All @@ -102,7 +103,7 @@ Granito::active_update(float dt_sec)
{
// Don't do any extra calculations
WalkingBadguy::active_update(dt_sec);
m_stepped_on = false;
m_has_entity_on_top = false;
return;
}

Expand All @@ -114,7 +115,7 @@ Granito::active_update(float dt_sec)
{
// Still waving
WalkingBadguy::active_update(dt_sec);
m_stepped_on = false;
m_has_entity_on_top = false;
return;
}
else
Expand Down Expand Up @@ -187,8 +188,7 @@ Granito::active_update(float dt_sec)
}

WalkingBadguy::active_update(dt_sec);

m_stepped_on = false;
m_has_entity_on_top = false;
}

HitResponse
Expand All @@ -198,7 +198,7 @@ Granito::collision_player(Player& player, const CollisionHit& hit)

if (hit.top)
{
m_stepped_on = true;
m_has_entity_on_top = true;

if (m_state != STATE_LOOKUP)
{
Expand All @@ -219,7 +219,26 @@ HitResponse
Granito::collision(MovingObject& other, const CollisionHit& hit)
{
if (hit.top)
m_col.propagate_movement(m_col.get_movement());
{
Rock* rock = dynamic_cast<Rock*>(&other);
if (rock)
{
if (m_state == STATE_SIT && get_carrier())
{
eject();
m_physic.reset();
}

m_has_entity_on_top = true;
walk_speed = 0;
m_physic.set_velocity_x(0);

m_state = STATE_LOOKUP;
set_action("lookup", m_dir);

goto granito_collision_end;
}
}

if (hit.bottom)
{
Expand Down Expand Up @@ -262,7 +281,6 @@ Granito::collision(MovingObject& other, const CollisionHit& hit)

// Call other collision functions (collision_player, collision_badguy, ...)
WalkingBadguy::collision(other, hit);

return FORCE_MOVE;
}

Expand Down
2 changes: 1 addition & 1 deletion src/badguy/granito.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class Granito : public WalkingBadguy
State m_original_state;

bool m_has_waved;
bool m_stepped_on; /** True if tux was on top of granito last frame. */
bool m_has_entity_on_top; /** True if any entity (player or object) was on top of the granito in the last frame. */
bool m_airborne; /** Unfortunately, on_ground() sucks. */

std::string m_detect_script;
Expand Down
8 changes: 8 additions & 0 deletions src/badguy/granito_big.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ GranitoBig::collision_player(Player& player, const CollisionHit& hit)
return FORCE_MOVE;
}

HitResponse GranitoBig::collision(MovingObject& other, const CollisionHit& hit)
{
// Prevent from triggering the collision logic of small granitos
return FORCE_MOVE;
}

void
GranitoBig::active_update(float dt_sec)
{
Granito::active_update(dt_sec);

m_col.propagate_movement(m_physic.get_movement(dt_sec));

if (!m_carrying)
return;

Expand Down
1 change: 1 addition & 0 deletions src/badguy/granito_big.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class GranitoBig final : public Granito
GranitoBig(const ReaderMapping& reader);

virtual HitResponse collision_player(Player& player, const CollisionHit& hit) override;
virtual HitResponse collision(MovingObject& other, const CollisionHit& hit) override;

virtual void active_update(float dt_sec) override;

Expand Down
6 changes: 6 additions & 0 deletions src/object/rock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "audio/sound_manager.hpp"
#include "badguy/crusher.hpp"
#include "badguy/badguy.hpp"
#include "badguy/granito_big.hpp"
#include "object/coin.hpp"
#include "object/explosion.hpp"
#include "object/lit_object.hpp"
Expand Down Expand Up @@ -222,6 +223,11 @@ Rock::collision(MovingObject& other, const CollisionHit& hit)
if (player) {
m_physic.set_velocity_y(-250.f);
}

const auto* granito = dynamic_cast<GranitoBig*>(&other);
if (granito) {
return ABORT_MOVE;
}
}

// Don't fall further if we are on a rock which is on the ground.
Expand Down
Loading