sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action);
bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed);
+ physic.set_acceleration_x (0.0);
}
void
WalkingBadguy::set_walk_speed (float ws)
{
walk_speed = fabs (ws);
- physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed);
+ /* physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed); */
}
void
-WalkingBadguy::active_update(float elapsed_time)
+WalkingBadguy::add_velocity (const Vector& velocity)
+{
+ physic.set_velocity(physic.get_velocity() + velocity);
+}
+
+void
+WalkingBadguy::active_update(float elapsed_time, float dest_x_velocity)
{
BadGuy::active_update(elapsed_time);
+ float current_x_velocity = physic.get_velocity_x ();
+
+ if (frozen)
+ {
+ physic.set_velocity_x (0.0);
+ physic.set_acceleration_x (0.0);
+ }
+ /* We're very close to our target speed. Just set it to avoid oscillation */
+ else if ((current_x_velocity > (dest_x_velocity - 5.0))
+ && (current_x_velocity < (dest_x_velocity + 5.0)))
+ {
+ physic.set_velocity_x (dest_x_velocity);
+ physic.set_acceleration_x (0.0);
+ }
+ /* Check if we're going too slow or even in the wrong direction */
+ 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 (((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. */
+ physic.set_acceleration_x ((-1.0) * dest_x_velocity);
+ }
+ else
+ {
+ /* The above should have covered all cases. */
+ assert (23 == 42);
+ }
+
if (max_drop_height > -1) {
if (on_ground() && might_fall(max_drop_height+1))
{
}
}
+ if ((dir == LEFT) && (physic.get_velocity_x () > 0.0)) {
+ dir = RIGHT;
+ set_action (walk_right_action, /* loops = */ -1);
+ }
+ else if ((dir == RIGHT) && (physic.get_velocity_x () < 0.0)) {
+ dir = LEFT;
+ set_action (walk_left_action, /* loops = */ -1);
+ }
+}
+
+void
+WalkingBadguy::active_update(float elapsed_time)
+{
+ this->active_update (elapsed_time, (dir == LEFT) ? -walk_speed : +walk_speed);
}
void
dir = dir == LEFT ? RIGHT : LEFT;
sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action);
physic.set_velocity_x(-physic.get_velocity_x());
+ physic.set_acceleration_x (-physic.get_acceleration_x ());
// if we get dizzy, we fall off the screen
if (turn_around_timer.started()) {