- should fix all cases of bad guys walking/bouncing backwards
[supertux.git] / src / badguy.cpp
index 9a2faef..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);
                 }
             }
         }
@@ -778,7 +779,8 @@ void
 BadGuy::bump()
 {
   // these can't be bumped
-  if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH)
+  if(kind == BAD_FLAME || kind == BAD_BOMB || kind == BAD_FISH
+      || kind == BAD_FLYINGSNOWBALL)
     return;
   
   kill_me(25);
@@ -989,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;
         }
@@ -1012,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);
           }
       }