From bc496de1184b0a70669736496ba198a368d10bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pale=C4=8Dek?= Date: Fri, 25 Aug 2023 20:36:46 +0200 Subject: [PATCH] Make thrown bombs explode on impact (#2586) Closes #2574. This PR implements the "explode on impact with other enemies" part + it makes thrown bombs explode on contact with the (a) player. As requested by Rusty, I made it so that the bombs will explode upon being thrown at walls and ceilings, but not floors. --- src/badguy/bomb.cpp | 12 +++++++----- src/badguy/goldbomb.cpp | 38 +++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/badguy/bomb.cpp b/src/badguy/bomb.cpp index 19942870e95..f4bc06b21bb 100644 --- a/src/badguy/bomb.cpp +++ b/src/badguy/bomb.cpp @@ -47,12 +47,10 @@ Bomb::collision_solid(const CollisionHit& hit) if (is_grabbed()) { return; } - if (hit.top || hit.bottom) + if (hit.bottom) m_physic.set_velocity_y(0); - if (hit.left || hit.right) - m_physic.set_velocity_x(-m_physic.get_velocity_x() * 0.5f); - if (hit.crush) - m_physic.set_velocity(0, 0); + else + explode(); update_on_ground_flag(hit); } @@ -60,12 +58,16 @@ Bomb::collision_solid(const CollisionHit& hit) HitResponse Bomb::collision_player(Player& , const CollisionHit& ) { + if (m_physic.get_velocity() != Vector()) + explode(); return ABORT_MOVE; } HitResponse Bomb::collision_badguy(BadGuy& , const CollisionHit& ) { + if (m_physic.get_velocity() != Vector()) + explode(); return ABORT_MOVE; } diff --git a/src/badguy/goldbomb.cpp b/src/badguy/goldbomb.cpp index 8a21303d540..671fab7c535 100644 --- a/src/badguy/goldbomb.cpp +++ b/src/badguy/goldbomb.cpp @@ -47,12 +47,11 @@ void GoldBomb::collision_solid(const CollisionHit& hit) { if (tstate == STATE_TICKING) { - if (hit.bottom) { + if (hit.bottom) m_physic.set_velocity(0, 0); - }else if (hit.left || hit.right) - m_physic.set_velocity_x(-m_physic.get_velocity_x()); - else if (hit.top) - m_physic.set_velocity_y(0); + else + kill_fall(); + update_on_ground_flag(hit); return; } @@ -62,16 +61,17 @@ GoldBomb::collision_solid(const CollisionHit& hit) HitResponse GoldBomb::collision(GameObject& object, const CollisionHit& hit) { - if (tstate == STATE_TICKING) { - if ( dynamic_cast(&object) ) { - return ABORT_MOVE; - } - if ( dynamic_cast(&object)) { - return ABORT_MOVE; - } + if (tstate == STATE_TICKING) + { + auto player = dynamic_cast(&object); + if (player) return collision_player(*player, hit); + auto badguy = dynamic_cast(&object); + if (badguy) return collision_badguy(*badguy, hit); } + if (is_grabbed()) return FORCE_MOVE; + return WalkingBadguy::collision(object, hit); } @@ -79,7 +79,11 @@ HitResponse GoldBomb::collision_player(Player& player, const CollisionHit& hit) { if (tstate == STATE_TICKING) - return FORCE_MOVE; + { + if (m_physic.get_velocity() != Vector()) + kill_fall(); + return ABORT_MOVE; + } if (is_grabbed()) return FORCE_MOVE; return BadGuy::collision_player(player, hit); @@ -89,7 +93,11 @@ HitResponse GoldBomb::collision_badguy(BadGuy& badguy, const CollisionHit& hit) { if (tstate == STATE_TICKING) - return FORCE_MOVE; + { + if (m_physic.get_velocity() != Vector()) + kill_fall(); + return ABORT_MOVE; + } return WalkingBadguy::collision_badguy(badguy, hit); } @@ -183,7 +191,7 @@ GoldBomb::kill_fall() EXPLOSION_STRENGTH_DEFAULT); run_dead_script(); } - Sector::get().add(get_pos() + Vector(0, -40), !m_parent_dispenser); + Sector::get().add(get_pos(), !m_parent_dispenser); } }