From a844c5d2b301ccf1f222257236250aaaefa26952 Mon Sep 17 00:00:00 2001 From: florianf Date: Fri, 5 Mar 2010 08:37:28 +0000 Subject: [PATCH] badguy/haywire.cpp: Use the x-acceleration to follow the player. This is a lot smoother and generally nicer than the previous (proof of concept) code. git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6552 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/badguy/haywire.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/badguy/haywire.cpp b/src/badguy/haywire.cpp index 225251570..293aa3f3c 100644 --- a/src/badguy/haywire.cpp +++ b/src/badguy/haywire.cpp @@ -106,6 +106,8 @@ Haywire::collision_squished(GameObject& object) time_stunned = TIME_STUNNED; is_stunned = true; + physic.set_velocity_x (0.0); + physic.set_acceleration_x (0.0); if (player) player->bounce (*this); @@ -137,21 +139,23 @@ Haywire::active_update(float elapsed_time) } } - if (is_exploding && !turn_around_timer.started()) { + if (is_exploding) { Player *p = this->get_nearest_player (); + float target_velocity = 0.0; if (p) { - Direction player_dir = LEFT; - + /* Player is on the right */ if (p->get_pos ().x > this->get_pos ().x) - player_dir = RIGHT; + target_velocity = walk_speed; + else /* player in on the left */ + target_velocity = (-1.0) * walk_speed; + } /* if (player) */ - if (player_dir != dir) - turn_around (); - } + WalkingBadguy::active_update(elapsed_time, target_velocity); + } + else { + WalkingBadguy::active_update(elapsed_time); } - - WalkingBadguy::active_update(elapsed_time); } void -- 2.11.0