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

Haywire Updates #1757

Merged
merged 4 commits into from
Jun 25, 2021
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
76 changes: 65 additions & 11 deletions src/badguy/haywire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -124,7 +124,44 @@ Haywire::active_update(float dt_sec)
}
}

if (is_exploding) {
if (is_exploding)
{
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";
Expand All @@ -139,19 +176,20 @@ 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 {
else
WalkingBadguy::active_update(dt_sec);
}
}

void
Expand Down Expand Up @@ -202,6 +240,7 @@ void
Haywire::start_exploding()
{
set_walk_speed (EXPLODING_WALK_SPEED);
max_drop_height = -1;
time_until_explosion = TIME_EXPLOSION;
is_exploding = true;

Expand All @@ -223,6 +262,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;

Expand Down Expand Up @@ -255,4 +295,18 @@ void Haywire::play_looping_sounds()
}
}

HitResponse Haywire::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
{
if (is_exploding)
{
badguy.kill_fall();
return FORCE_MOVE;
}
else
{
WalkingBadguy::collision_badguy(badguy, hit);
}
return ABORT_MOVE;
}

/* EOF */
2 changes: 2 additions & 0 deletions src/badguy/haywire.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"); }

Expand Down
4 changes: 2 additions & 2 deletions src/badguy/walking_badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)) ||
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/walking_badguy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down