Skip to content

Commit afb12af

Browse files
authored
Haywire Updates (#1757)
* Haywire acceleration improvements * Haywire AI updates * Haywire kills bystanders * Code quality
1 parent a58c844 commit afb12af

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

src/badguy/haywire.cpp

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const float STOMPED_TIME = 1.0f;
3232
const float TIME_STUNNED = 0.5f;
3333

3434
const float NORMAL_WALK_SPEED = 80.0f;
35-
const float EXPLODING_WALK_SPEED = 160.0f;
35+
const float EXPLODING_WALK_SPEED = 200.0f;
3636

3737
} // namespace
3838

@@ -124,7 +124,44 @@ Haywire::active_update(float dt_sec)
124124
}
125125
}
126126

127-
if (is_exploding) {
127+
if (is_exploding)
128+
{
129+
if (on_ground() && std::abs(m_physic.get_velocity_x()) > 40.f)
130+
{
131+
//jump over 1-tall roadblocks
132+
Rectf jump_box = get_bbox();
133+
jump_box.set_left(m_col.m_bbox.get_left() + (m_dir == Direction::LEFT ? -48.f : 38.f));
134+
jump_box.set_right(m_col.m_bbox.get_right() + (m_dir == Direction::RIGHT ? 48.f : -38.f));
135+
136+
Rectf exception_box = get_bbox();
137+
exception_box.set_left(m_col.m_bbox.get_left() + (m_dir == Direction::LEFT ? -48.f : 38.f));
138+
exception_box.set_right(m_col.m_bbox.get_right() + (m_dir == Direction::RIGHT ? 48.f : -38.f));
139+
exception_box.set_top(m_col.m_bbox.get_top() - 32.f);
140+
exception_box.set_bottom(m_col.m_bbox.get_bottom() - 48.f);
141+
142+
if (!Sector::get().is_free_of_statics(jump_box) && Sector::get().is_free_of_statics(exception_box))
143+
{
144+
m_physic.set_velocity_y(-325.f);
145+
}
146+
else
147+
{
148+
//jump over gaps if Tux isnt below
149+
Rectf gap_box = get_bbox();
150+
gap_box.set_left(m_col.m_bbox.get_left() + (m_dir == Direction::LEFT ? -38.f : 26.f));
151+
gap_box.set_right(m_col.m_bbox.get_right() + (m_dir == Direction::LEFT ? -26.f : 38.f));
152+
gap_box.set_top(m_col.m_bbox.get_top());
153+
gap_box.set_bottom(m_col.m_bbox.get_bottom() + 28.f);
154+
155+
if (Sector::get().is_free_of_statics(gap_box)
156+
&& (get_nearest_player()->get_bbox().get_bottom() <= m_col.m_bbox.get_bottom()))
157+
{
158+
m_physic.set_velocity_y(-325.f);
159+
}
160+
}
161+
}
162+
163+
//end of pathfinding
164+
128165
if (stomped_timer.get_timeleft() < 0.05f) {
129166
set_action ((m_dir == Direction::LEFT) ? "ticking-left" : "ticking-right", /* loops = */ -1);
130167
walk_left_action = "ticking-left";
@@ -139,19 +176,20 @@ Haywire::active_update(float dt_sec)
139176
auto p = get_nearest_player ();
140177
float target_velocity = 0.f;
141178

142-
if (p && time_stunned == 0.0f) {
143-
/* Player is on the right */
144-
if (p->get_pos ().x > get_pos ().x)
145-
target_velocity = walk_speed;
146-
else /* player in on the left */
147-
target_velocity = (-1.f) * walk_speed;
179+
if (stomped_timer.get_timeleft() >= 0.05f)
180+
{
181+
target_velocity = 0.f;
182+
}
183+
else if (p && time_stunned == 0.0f)
184+
{
185+
/* Player is on the right or left*/
186+
target_velocity = (p->get_pos().x > get_pos().x) ? walk_speed : (-1.f) * walk_speed;
148187
}
149188

150-
WalkingBadguy::active_update(dt_sec, target_velocity);
189+
WalkingBadguy::active_update(dt_sec, target_velocity, 3.f);
151190
}
152-
else {
191+
else
153192
WalkingBadguy::active_update(dt_sec);
154-
}
155193
}
156194

157195
void
@@ -202,6 +240,7 @@ void
202240
Haywire::start_exploding()
203241
{
204242
set_walk_speed (EXPLODING_WALK_SPEED);
243+
max_drop_height = -1;
205244
time_until_explosion = TIME_EXPLOSION;
206245
is_exploding = true;
207246

@@ -223,6 +262,7 @@ Haywire::stop_exploding()
223262
walk_left_action = "left";
224263
walk_right_action = "right";
225264
set_walk_speed(NORMAL_WALK_SPEED);
265+
max_drop_height = 16;
226266
time_until_explosion = 0.0f;
227267
is_exploding = false;
228268

@@ -255,4 +295,18 @@ void Haywire::play_looping_sounds()
255295
}
256296
}
257297

298+
HitResponse Haywire::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
299+
{
300+
if (is_exploding)
301+
{
302+
badguy.kill_fall();
303+
return FORCE_MOVE;
304+
}
305+
else
306+
{
307+
WalkingBadguy::collision_badguy(badguy, hit);
308+
}
309+
return ABORT_MOVE;
310+
}
311+
258312
/* EOF */

src/badguy/haywire.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class Haywire final : public WalkingBadguy
3939
virtual void stop_looping_sounds() override;
4040
virtual void play_looping_sounds() override;
4141

42+
virtual HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit) override;
43+
4244
virtual std::string get_class() const override { return "haywire"; }
4345
virtual std::string get_display_name() const override { return _("Haywire"); }
4446

src/badguy/walking_badguy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ WalkingBadguy::add_velocity (const Vector& velocity)
9494
}
9595

9696
void
97-
WalkingBadguy::active_update(float dt_sec, float dest_x_velocity)
97+
WalkingBadguy::active_update(float dt_sec, float dest_x_velocity, float modifier)
9898
{
9999
BadGuy::active_update(dt_sec);
100100

@@ -118,7 +118,7 @@ WalkingBadguy::active_update(float dt_sec, float dest_x_velocity)
118118
{
119119
/* acceleration == walk-speed => it will take one second to get from zero
120120
* to full speed. */
121-
m_physic.set_acceleration_x (dest_x_velocity);
121+
m_physic.set_acceleration_x (dest_x_velocity * modifier);
122122
}
123123
/* Check if we're going too fast */
124124
else if (((dest_x_velocity <= 0.0f) && (current_x_velocity < dest_x_velocity)) ||

src/badguy/walking_badguy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class WalkingBadguy : public BadGuy
5151
virtual void freeze() override;
5252
virtual void unfreeze() override;
5353

54-
void active_update(float dt_sec, float target_velocity);
54+
void active_update(float dt_sec, float target_velocity, float modifier = 1.f);
5555

5656
float get_velocity_x() const { return m_physic.get_velocity_x(); }
5757
float get_velocity_y() const { return m_physic.get_velocity_y(); }

0 commit comments

Comments
 (0)