Skip to content

Commit

Permalink
badguy/haywire.cpp: Use the x-acceleration to follow the player.
Browse files Browse the repository at this point in the history
This is a lot smoother and generally nicer than the previous (proof of concept)
code.

SVN-Revision: 6552
  • Loading branch information
Florian Forster committed Mar 5, 2010
1 parent 5e823b8 commit 1668c3c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/badguy/haywire.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1668c3c

Please sign in to comment.