From: Florian Forster Date: Fri, 5 Mar 2010 08:27:35 +0000 (+0000) Subject: badguy/walking_badguy.[ch]pp: Make it possible to specify the target x velocity. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=30dcd6e1e68ee1c467384a575a978da580fc7640;p=supertux.git badguy/walking_badguy.[ch]pp: Make it possible to specify the target x velocity. This will be use by "Haywire" eventually to get a more smooth "follow the player" effect. SVN-Revision: 6550 --- diff --git a/src/badguy/walking_badguy.cpp b/src/badguy/walking_badguy.cpp index 1d4cf159f..8ab7d35ed 100644 --- a/src/badguy/walking_badguy.cpp +++ b/src/badguy/walking_badguy.cpp @@ -91,12 +91,11 @@ WalkingBadguy::add_velocity (const Vector& velocity) } void -WalkingBadguy::active_update(float elapsed_time) +WalkingBadguy::active_update(float elapsed_time, float dest_x_velocity) { BadGuy::active_update(elapsed_time); float current_x_velocity = physic.get_velocity_x (); - float dest_x_velocity = (dir == LEFT) ? -walk_speed : +walk_speed; if (frozen) { @@ -111,16 +110,16 @@ WalkingBadguy::active_update(float elapsed_time) physic.set_acceleration_x (0.0); } /* Check if we're going too slow or even in the wrong direction */ - else if (((dir == LEFT) && (current_x_velocity > dest_x_velocity)) - || ((dir == RIGHT) && (current_x_velocity < dest_x_velocity))) + else if (((dest_x_velocity <= 0.0) && (current_x_velocity > dest_x_velocity)) + || ((dest_x_velocity > 0.0) && (current_x_velocity < dest_x_velocity))) { /* acceleration == walk-speed => it will take one second to get from zero * to full speed. */ physic.set_acceleration_x (dest_x_velocity); } /* Check if we're going too fast */ - else if (((dir == LEFT) && (current_x_velocity < dest_x_velocity)) - || ((dir == RIGHT) && (current_x_velocity > dest_x_velocity))) + else if (((dest_x_velocity <= 0.0) && (current_x_velocity < dest_x_velocity)) + || ((dest_x_velocity > 0.0) && (current_x_velocity > dest_x_velocity))) { /* acceleration == walk-speed => it will take one second to get twice the * speed to normal speed. */ @@ -141,6 +140,12 @@ WalkingBadguy::active_update(float elapsed_time) } void +WalkingBadguy::active_update(float elapsed_time) +{ + this->active_update (elapsed_time, (dir == LEFT) ? -walk_speed : +walk_speed); +} + +void WalkingBadguy::collision_solid(const CollisionHit& hit) { diff --git a/src/badguy/walking_badguy.hpp b/src/badguy/walking_badguy.hpp index 4bfb4556a..038d87668 100644 --- a/src/badguy/walking_badguy.hpp +++ b/src/badguy/walking_badguy.hpp @@ -45,6 +45,7 @@ public: void initialize(); void active_update(float elapsed_time); + void active_update(float elapsed_time, float target_velocity); void collision_solid(const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); void freeze();