From: Ryan Flegel Date: Fri, 30 Apr 2004 01:23:15 +0000 (+0000) Subject: - should fix all cases of bad guys walking/bouncing backwards X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=697710a2b7e03f957b8af194bc87ef78147c4086;p=supertux.git - should fix all cases of bad guys walking/bouncing backwards SVN-Revision: 857 --- diff --git a/src/badguy.cpp b/src/badguy.cpp index 9fbaba8ad..4b9a15075 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -345,11 +345,12 @@ BadGuy::fall() if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width), base.y + base.height)) { - physic.set_velocity_x(-physic.get_velocity_x()); if (dir == LEFT) dir = RIGHT; else dir = LEFT; + + physic.set_velocity_x(fabs(physic.get_velocity_x()) * dir == LEFT ? -1 : 1); } } } @@ -990,16 +991,12 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type) // Bounce off of other badguy if we land on top of him if (base.y + base.height < pbad_c->base.y + pbad_c->base.height) { - Direction old_dir = dir; if (pbad_c->dir == LEFT) dir = RIGHT; else if (pbad_c->dir == RIGHT) dir = LEFT; - if (dir != old_dir) - physic.inverse_velocity_x(); - - physic.set_velocity(fabs(physic.get_velocity_x()), 2); + physic.set_velocity(fabs(physic.get_velocity_x()) * dir == LEFT ? -1 : 1, 2); break; } @@ -1013,7 +1010,7 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type) else if (dir == RIGHT) dir = LEFT; - physic.inverse_velocity_x(); + physic.set_velocity_x(fabs(physic.get_velocity_x()) * dir == LEFT ? -1 : 1); } }