Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various crusher fixes #3047

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
45 changes: 30 additions & 15 deletions src/badguy/crusher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,40 @@ HitResponse
Crusher::collision(GameObject& other, const CollisionHit& hit)
{
auto* player = dynamic_cast<Player*>(&other);
bool crushed_bottom = m_state == CRUSHING && !m_sideways && hit.bottom;
bool crushed_sideways = m_state == CRUSHING && m_sideways &&
((hit.left && m_physic.get_velocity_x() < 0.f) ||
(hit.right && m_physic.get_velocity_x() > 0.f));
bool is_crushing = crushed_bottom || crushed_sideways;

// If the other object is the player, and the collision is at the
// bottom of the crusher, hurt the player.
Comment on lines 132 to 133
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't reflect the changes (sideways collision also now hurts the player).

if (player && hit.bottom && player->on_ground() && m_state == CRUSHING) {
if (player && is_crushing &&
((crushed_bottom && player->on_ground()) || crushed_sideways)) {
SoundManager::current()->play("sounds/brick.wav", get_pos());
set_state(RECOVERING);
if (player->is_invincible()) {
return ABORT_MOVE;
}
if(crushed_sideways)
{
// TODO: Is there a better method than introducing
// a completely new player method (e.g. by returning
// ABORT_MOVE from this function)?
player->ignore_sideways_crush();
}
player->kill(false);
return FORCE_MOVE;
}

auto* badguy = dynamic_cast<BadGuy*>(&other);
if (badguy && m_state == CRUSHING && ((!m_sideways && hit.bottom) ||
(m_sideways && ((hit.left && m_physic.get_velocity_x() < 0.f) ||
(hit.right && m_physic.get_velocity_x() > 0.f)))))
if (badguy && is_crushing)
{
badguy->kill_fall();
}

auto* rock = dynamic_cast<Rock*>(&other);
if (rock && !rock->is_grabbed() && m_state == CRUSHING && ((!m_sideways && hit.bottom) ||
(m_sideways && ((hit.left && m_physic.get_velocity_x() < 0.f) ||
(hit.right && m_physic.get_velocity_x() > 0.f)))))
if (rock && !rock->is_grabbed() && is_crushing)
{
SoundManager::current()->play("sounds/brick.wav", get_pos());
m_physic.reset();
Expand Down Expand Up @@ -226,14 +235,20 @@ Crusher::collision_solid(const CollisionHit& hit)
}
}
}
if (hit.bottom)
spawn_roots(Direction::DOWN);
else if (hit.top)
spawn_roots(Direction::UP);
else if (hit.left)
spawn_roots(Direction::LEFT);
else if (hit.right)
spawn_roots(Direction::RIGHT);
if(m_sideways)
{
if (hit.left)
spawn_roots(Direction::LEFT);
else if (hit.right)
spawn_roots(Direction::RIGHT);
}
else
{
if (hit.bottom)
spawn_roots(Direction::DOWN);
else if (hit.top)
spawn_roots(Direction::UP);
}
break;
default:
log_debug << "Crusher in invalid state" << std::endl;
Expand Down
10 changes: 8 additions & 2 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ Player::Player(PlayerStatus& player_status, const std::string& name_, int player
m_jump_early_apex(false),
m_on_ice(false),
m_ice_this_frame(false),
m_ignore_sideways_crush(false),
//m_santahatsprite(SpriteManager::current()->create("images/creatures/tux/santahat.sprite")),
m_multiplayer_arrow(SpriteManager::current()->create("images/engine/hud/arrowdown.png")),
m_tag_timer(),
Expand Down Expand Up @@ -2324,8 +2325,13 @@ Player::collision_solid(const CollisionHit& hit)

// crushed?
if (hit.crush) {
if (hit.left || hit.right) {
kill(true);
if ((hit.left || hit.right)) {
if (m_ignore_sideways_crush) {
m_ignore_sideways_crush = false;
}
else {
kill(true);
}
Comment on lines +2328 to +2334
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tux isn't killed immediately when crushed vertically, then why can't it also happen here? This way you remove the ignore_sidways_crush thing. But I might be missing something

Comment on lines +2328 to +2334
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we make it so that despite of the side where Tux was hit from, kill(false) is performed? Is there a reason for sideways crushing to instantly kill Tux with kill(true)?

If we do that, m_ignore_sideways_crush wouldn't be needed.

} else if (hit.top || hit.bottom) {
kill(false);
}
Expand Down
2 changes: 2 additions & 0 deletions src/object/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ class Player final : public MovingObject
void remove_collected_key(Key* key);

bool track_state() const override { return false; }
void ignore_sideways_crush() { m_ignore_sideways_crush = true; }

private:
void handle_input();
Expand Down Expand Up @@ -500,6 +501,7 @@ class Player final : public MovingObject
bool m_jump_early_apex;
bool m_on_ice;
bool m_ice_this_frame;
bool m_ignore_sideways_crush;
//SpritePtr m_santahatsprite;
SpritePtr m_multiplayer_arrow;

Expand Down
Loading