From e0c7b06b4428b708c4e31a4b727ae625b0b26037 Mon Sep 17 00:00:00 2001 From: weluvgoatz Date: Mon, 24 May 2021 10:40:49 -0700 Subject: [PATCH 1/4] Haywire acceleration improvements --- src/badguy/haywire.cpp | 18 ++++++++++-------- src/badguy/walking_badguy.cpp | 4 ++-- src/badguy/walking_badguy.hpp | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/badguy/haywire.cpp b/src/badguy/haywire.cpp index 08b611b5d23..9ebfe3256aa 100644 --- a/src/badguy/haywire.cpp +++ b/src/badguy/haywire.cpp @@ -32,7 +32,7 @@ const float STOMPED_TIME = 1.0f; const float TIME_STUNNED = 0.5f; const float NORMAL_WALK_SPEED = 80.0f; -const float EXPLODING_WALK_SPEED = 160.0f; +const float EXPLODING_WALK_SPEED = 200.0f; } // namespace @@ -139,15 +139,17 @@ Haywire::active_update(float dt_sec) auto p = get_nearest_player (); float target_velocity = 0.f; - if (p && time_stunned == 0.0f) { - /* Player is on the right */ - if (p->get_pos ().x > get_pos ().x) - target_velocity = walk_speed; - else /* player in on the left */ - target_velocity = (-1.f) * walk_speed; + if (stomped_timer.get_timeleft() >= 0.05f) + { + target_velocity = 0.f; + } + else if (p && time_stunned == 0.0f) + { + /* Player is on the right or left*/ + target_velocity = (p->get_pos().x > get_pos().x) ? walk_speed : (-1.f) * walk_speed; } - WalkingBadguy::active_update(dt_sec, target_velocity); + WalkingBadguy::active_update(dt_sec, target_velocity, 3.f); } else { WalkingBadguy::active_update(dt_sec); diff --git a/src/badguy/walking_badguy.cpp b/src/badguy/walking_badguy.cpp index 26bd7ee247c..5ae987eb0c0 100644 --- a/src/badguy/walking_badguy.cpp +++ b/src/badguy/walking_badguy.cpp @@ -94,7 +94,7 @@ WalkingBadguy::add_velocity (const Vector& velocity) } void -WalkingBadguy::active_update(float dt_sec, float dest_x_velocity) +WalkingBadguy::active_update(float dt_sec, float dest_x_velocity, float modifier) { BadGuy::active_update(dt_sec); @@ -118,7 +118,7 @@ WalkingBadguy::active_update(float dt_sec, float dest_x_velocity) { /* acceleration == walk-speed => it will take one second to get from zero * to full speed. */ - m_physic.set_acceleration_x (dest_x_velocity); + m_physic.set_acceleration_x (dest_x_velocity * modifier); } /* Check if we're going too fast */ else if (((dest_x_velocity <= 0.0f) && (current_x_velocity < dest_x_velocity)) || diff --git a/src/badguy/walking_badguy.hpp b/src/badguy/walking_badguy.hpp index 1bf8ea032f6..48e2aa5cabb 100644 --- a/src/badguy/walking_badguy.hpp +++ b/src/badguy/walking_badguy.hpp @@ -51,7 +51,7 @@ class WalkingBadguy : public BadGuy virtual void freeze() override; virtual void unfreeze() override; - void active_update(float dt_sec, float target_velocity); + void active_update(float dt_sec, float target_velocity, float modifier = 1.f); float get_velocity_x() const { return m_physic.get_velocity_x(); } float get_velocity_y() const { return m_physic.get_velocity_y(); } From 06882040ecc79f83c2d8c1a33f3a2a49b39292a3 Mon Sep 17 00:00:00 2001 From: weluvgoatz Date: Tue, 25 May 2021 13:12:11 -0700 Subject: [PATCH 2/4] Haywire AI updates --- src/badguy/haywire.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++ src/badguy/haywire.hpp | 2 ++ 2 files changed, 77 insertions(+) diff --git a/src/badguy/haywire.cpp b/src/badguy/haywire.cpp index 9ebfe3256aa..0fcc41fedad 100644 --- a/src/badguy/haywire.cpp +++ b/src/badguy/haywire.cpp @@ -125,6 +125,56 @@ Haywire::active_update(float dt_sec) } if (is_exploding) { + //jump over enemies + for (auto& enemy : Sector::get().get_objects_by_type()) + { + Rectf enemy_bbox = enemy.get_bbox(); + if ((enemy_bbox.get_left() < (m_col.m_bbox.get_right() + (m_dir == Direction::RIGHT ? 48.f : -38.f))) + && (enemy_bbox.get_right() > (m_col.m_bbox.get_left() + (m_dir == Direction::LEFT ? -48.f : 38.f))) + && (enemy_bbox.get_bottom() < (m_col.m_bbox.get_bottom() + 6.f)) + && (enemy_bbox.get_top() > (m_col.m_bbox.get_top() - 6.f)) + && on_ground() && std::abs(m_physic.get_velocity_x()) > 40.f) + { + m_physic.set_velocity_y(-325.f); + } + } + + if (on_ground() && std::abs(m_physic.get_velocity_x()) > 40.f) + { + //jump over 1-tall roadblocks + Rectf jump_box = get_bbox(); + jump_box.set_left(m_col.m_bbox.get_left() + (m_dir == Direction::LEFT ? -48.f : 38.f)); + jump_box.set_right(m_col.m_bbox.get_right() + (m_dir == Direction::RIGHT ? 48.f : -38.f)); + + Rectf exception_box = get_bbox(); + exception_box.set_left(m_col.m_bbox.get_left() + (m_dir == Direction::LEFT ? -48.f : 38.f)); + exception_box.set_right(m_col.m_bbox.get_right() + (m_dir == Direction::RIGHT ? 48.f : -38.f)); + exception_box.set_top(m_col.m_bbox.get_top() - 32.f); + exception_box.set_bottom(m_col.m_bbox.get_bottom() - 48.f); + + if (!Sector::get().is_free_of_statics(jump_box) && Sector::get().is_free_of_statics(exception_box)) + { + m_physic.set_velocity_y(-325.f); + } + else + { + //jump over gaps if Tux isnt below + Rectf gap_box = get_bbox(); + gap_box.set_left(m_col.m_bbox.get_left() + (m_dir == Direction::LEFT ? -38.f : 26.f)); + gap_box.set_right(m_col.m_bbox.get_right() + (m_dir == Direction::LEFT ? -26.f : 38.f)); + gap_box.set_top(m_col.m_bbox.get_top()); + gap_box.set_bottom(m_col.m_bbox.get_bottom() + 28.f); + + if (Sector::get().is_free_of_statics(gap_box) + && (get_nearest_player()->get_bbox().get_bottom() <= m_col.m_bbox.get_bottom())) + { + m_physic.set_velocity_y(-325.f); + } + } + } + + //end of pathfinding + if (stomped_timer.get_timeleft() < 0.05f) { set_action ((m_dir == Direction::LEFT) ? "ticking-left" : "ticking-right", /* loops = */ -1); walk_left_action = "ticking-left"; @@ -204,6 +254,7 @@ void Haywire::start_exploding() { set_walk_speed (EXPLODING_WALK_SPEED); + max_drop_height = -1; time_until_explosion = TIME_EXPLOSION; is_exploding = true; @@ -225,6 +276,7 @@ Haywire::stop_exploding() walk_left_action = "left"; walk_right_action = "right"; set_walk_speed(NORMAL_WALK_SPEED); + max_drop_height = 16; time_until_explosion = 0.0f; is_exploding = false; @@ -257,4 +309,27 @@ void Haywire::play_looping_sounds() } } +HitResponse Haywire::collision_badguy(BadGuy&, const CollisionHit& hit) +{ + if (hit.top) + { + return FORCE_MOVE; + } + if (is_exploding) + { + if (hit.bottom) + { + m_physic.set_velocity_y(-325.f); + } + } + else + { + if ((hit.left && (m_dir == Direction::LEFT)) || (hit.right && (m_dir == Direction::RIGHT))) + { + turn_around(); + } + } + return CONTINUE; +} + /* EOF */ diff --git a/src/badguy/haywire.hpp b/src/badguy/haywire.hpp index ffa79a2884c..1407d80d143 100644 --- a/src/badguy/haywire.hpp +++ b/src/badguy/haywire.hpp @@ -39,6 +39,8 @@ class Haywire final : public WalkingBadguy virtual void stop_looping_sounds() override; virtual void play_looping_sounds() override; + virtual HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit) override; + virtual std::string get_class() const override { return "haywire"; } virtual std::string get_display_name() const override { return _("Haywire"); } From b6c73d34fedc327427446449e62f437954766097 Mon Sep 17 00:00:00 2001 From: weluvgoatz Date: Tue, 25 May 2021 14:33:20 -0700 Subject: [PATCH 3/4] Haywire kills bystanders --- src/badguy/haywire.cpp | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/src/badguy/haywire.cpp b/src/badguy/haywire.cpp index 0fcc41fedad..476ac4a5ad7 100644 --- a/src/badguy/haywire.cpp +++ b/src/badguy/haywire.cpp @@ -124,21 +124,8 @@ Haywire::active_update(float dt_sec) } } - if (is_exploding) { - //jump over enemies - for (auto& enemy : Sector::get().get_objects_by_type()) - { - Rectf enemy_bbox = enemy.get_bbox(); - if ((enemy_bbox.get_left() < (m_col.m_bbox.get_right() + (m_dir == Direction::RIGHT ? 48.f : -38.f))) - && (enemy_bbox.get_right() > (m_col.m_bbox.get_left() + (m_dir == Direction::LEFT ? -48.f : 38.f))) - && (enemy_bbox.get_bottom() < (m_col.m_bbox.get_bottom() + 6.f)) - && (enemy_bbox.get_top() > (m_col.m_bbox.get_top() - 6.f)) - && on_ground() && std::abs(m_physic.get_velocity_x()) > 40.f) - { - m_physic.set_velocity_y(-325.f); - } - } - + if (is_exploding) + { if (on_ground() && std::abs(m_physic.get_velocity_x()) > 40.f) { //jump over 1-tall roadblocks @@ -201,9 +188,8 @@ Haywire::active_update(float dt_sec) WalkingBadguy::active_update(dt_sec, target_velocity, 3.f); } - else { + else WalkingBadguy::active_update(dt_sec); - } } void @@ -309,27 +295,16 @@ void Haywire::play_looping_sounds() } } -HitResponse Haywire::collision_badguy(BadGuy&, const CollisionHit& hit) +HitResponse Haywire::collision_badguy(BadGuy& badguy, const CollisionHit& hit) { - if (hit.top) - { - return FORCE_MOVE; - } if (is_exploding) { - if (hit.bottom) - { - m_physic.set_velocity_y(-325.f); - } + badguy.kill_fall(); + return FORCE_MOVE; } else - { - if ((hit.left && (m_dir == Direction::LEFT)) || (hit.right && (m_dir == Direction::RIGHT))) - { - turn_around(); - } - } - return CONTINUE; + WalkingBadguy::collision_badguy(badguy, hit); + return ABORT_MOVE; } /* EOF */ From bd02db41cb50e7f19a0ab69052ff05d7f7a7aa7d Mon Sep 17 00:00:00 2001 From: weluvgoatz Date: Thu, 24 Jun 2021 17:42:06 -0700 Subject: [PATCH 4/4] Code quality --- src/badguy/haywire.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/badguy/haywire.cpp b/src/badguy/haywire.cpp index 476ac4a5ad7..8b07eace560 100644 --- a/src/badguy/haywire.cpp +++ b/src/badguy/haywire.cpp @@ -183,7 +183,7 @@ Haywire::active_update(float dt_sec) else if (p && time_stunned == 0.0f) { /* Player is on the right or left*/ - target_velocity = (p->get_pos().x > get_pos().x) ? walk_speed : (-1.f) * walk_speed; + target_velocity = (p->get_pos().x > get_pos().x) ? walk_speed : (-1.f) * walk_speed; } WalkingBadguy::active_update(dt_sec, target_velocity, 3.f); @@ -303,7 +303,9 @@ HitResponse Haywire::collision_badguy(BadGuy& badguy, const CollisionHit& hit) return FORCE_MOVE; } else + { WalkingBadguy::collision_badguy(badguy, hit); + } return ABORT_MOVE; }