From: Florian Forster Date: Fri, 5 Mar 2010 08:37:28 +0000 (+0000) Subject: badguy/haywire.cpp: Use the x-acceleration to follow the player. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1668c3cfe8bca9a396f2a00b857097fa693bc079;p=supertux.git 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. SVN-Revision: 6552 --- 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