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

Make thrown bombs explode on impact #2586

Merged
merged 4 commits into from
Aug 25, 2023
Merged
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
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
Loading