- should fix all cases of bad guys walking/bouncing backwards
authorRyan Flegel <rflegel@gmail.com>
Fri, 30 Apr 2004 01:23:15 +0000 (01:23 +0000)
committerRyan Flegel <rflegel@gmail.com>
Fri, 30 Apr 2004 01:23:15 +0000 (01:23 +0000)
SVN-Revision: 857

src/badguy.cpp

index 9fbaba8..4b9a150 100644 (file)
@@ -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);
           }
       }