Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Florian Forster committed Mar 5, 2010
1 parent 8c0f32d commit 30dcd6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/badguy/walking_badguy.cpp
Expand Up @@ -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)
{
Expand All @@ -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. */
Expand All @@ -140,6 +139,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)
{
Expand Down
1 change: 1 addition & 0 deletions src/badguy/walking_badguy.hpp
Expand Up @@ -45,6 +45,7 @@ class WalkingBadguy : public BadGuy

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();
Expand Down

0 comments on commit 30dcd6e

Please sign in to comment.