Skip to content

Commit

Permalink
Make thrown bombs explode on impact (#2586)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Narre authored Aug 25, 2023
1 parent 6bf9b3f commit bc496de
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
12 changes: 7 additions & 5 deletions src/badguy/bomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,27 @@ 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);
}

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;
}

Expand Down
38 changes: 23 additions & 15 deletions src/badguy/goldbomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -62,24 +61,29 @@ GoldBomb::collision_solid(const CollisionHit& hit)
HitResponse
GoldBomb::collision(GameObject& object, const CollisionHit& hit)
{
if (tstate == STATE_TICKING) {
if ( dynamic_cast<Player*>(&object) ) {
return ABORT_MOVE;
}
if ( dynamic_cast<BadGuy*>(&object)) {
return ABORT_MOVE;
}
if (tstate == STATE_TICKING)
{
auto player = dynamic_cast<Player*>(&object);
if (player) return collision_player(*player, hit);
auto badguy = dynamic_cast<BadGuy*>(&object);
if (badguy) return collision_badguy(*badguy, hit);
}

if (is_grabbed())
return FORCE_MOVE;

return WalkingBadguy::collision(object, hit);
}

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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -183,7 +191,7 @@ GoldBomb::kill_fall()
EXPLOSION_STRENGTH_DEFAULT);
run_dead_script();
}
Sector::get().add<CoinExplode>(get_pos() + Vector(0, -40), !m_parent_dispenser);
Sector::get().add<CoinExplode>(get_pos(), !m_parent_dispenser);
}
}

Expand Down

0 comments on commit bc496de

Please sign in to comment.