- turned LEFT/RIGHT defines into enum, turned BadGuyModes into enum
[supertux.git] / src / player.cpp
index 5018a61..7fb2206 100644 (file)
@@ -183,17 +183,27 @@ Player::action(double frame_ratio)
   previous_base = base;
 
   physic.apply(frame_ratio, base.x, base.y);
-  if(dying == DYING_NOT) {
+  if(dying == DYING_NOT) 
+    {
+      base_type target = base;
+
       collision_swept_object_map(&old_base, &base);
+
+      // Don't accelerate Tux if he is running against a wall
+      if (target.x != base.x)
+        {
+          physic.set_velocity_x(0);
+        }
+
       // special exception for cases where we're stuck under tiles after
       // being ducked. In this case we drift out
       if(!duck && on_ground() && old_base.x == base.x && old_base.y == base.y
-              && collision_object_map(&base)) {
-          base.x += frame_ratio * WALK_SPEED * (dir ? 1 : -1);
-          previous_base = old_base = base;
+         && collision_object_map(&base)) {
+        base.x += frame_ratio * WALK_SPEED * (dir ? 1 : -1);
+        previous_base = old_base = base;
       }
       keep_in_bounds();
-  }
+    }
 
   if (dying == DYING_NOT)
     {
@@ -206,7 +216,7 @@ Player::action(double frame_ratio)
           if(under_solid())
             {
               // fall down
-              physic.set_velocity(physic.get_velocity_x(), 0);
+              physic.set_velocity_y(0);
               jumped_in_solid = true;
             }
         }
@@ -216,7 +226,7 @@ Player::action(double frame_ratio)
           if (physic.get_velocity_y() < 0)
             {
               base.y = (int)(((int)base.y / 32) * 32);
-              physic.set_velocity(physic.get_velocity_x(), 0);
+              physic.set_velocity_y(0);
             }
 
           physic.enable_gravity(false);
@@ -273,10 +283,10 @@ Player::action(double frame_ratio)
   if (get_current_music() == HERRING_MUSIC && !invincible_timer.check())
     {
       /*
-         no, we are no more invincible
-         or we were not in invincible mode
-         but are we in hurry ?
-       */
+        no, we are no more invincible
+        or we were not in invincible mode
+        but are we in hurry ?
+      */
 
       // FIXME: Move this to gamesession
       if (GameSession::current()->time_left.get_left() < TIME_WARNING)
@@ -284,7 +294,7 @@ Player::action(double frame_ratio)
           /* yes, we are in hurry
              stop the herring_song, prepare to play the correct
              fast level_song !
-           */
+          */
           set_current_music(HURRYUP_MUSIC);
         }
       else
@@ -410,7 +420,11 @@ Player::handle_vertical_input()
       if (on_ground())
         {
           // jump
-          physic.set_velocity(physic.get_velocity_x(), 5.5);
+          if (physic.get_velocity_x() > MAX_WALK_XM)
+            physic.set_velocity_y(5.8);
+          else
+            physic.set_velocity_y(5.2);
+
           --base.y;
           jumping = true;
           if (size == SMALL)
@@ -423,7 +437,7 @@ Player::handle_vertical_input()
     {
       jumping = false;
       if(physic.get_velocity_y() > 0) {
-        physic.set_velocity(physic.get_velocity_x(), 0);
+        physic.set_velocity_y(0);
       }
     }
 }
@@ -688,18 +702,18 @@ Player::collision(void* p_c_object, int c_object)
      /* Hurt player if he touches a badguy */
       if (!pbad_c->dying && !dying &&
           !safe_timer.started() &&
-          pbad_c->mode != HELD)
+          pbad_c->mode != BadGuy::HELD)
         {
-          if (pbad_c->mode == FLAT && input.fire == DOWN)
+          if (pbad_c->mode == BadGuy::FLAT && input.fire == DOWN)
             {
-              pbad_c->mode = HELD;
+              pbad_c->mode = BadGuy::HELD;
               pbad_c->base.y-=8;
             }
-          else if (pbad_c->mode == FLAT)
+          else if (pbad_c->mode == BadGuy::FLAT)
             {
               // Don't get hurt if we're kicking a flat badguy!
             }
-          else if (pbad_c->mode == KICK)
+          else if (pbad_c->mode == BadGuy::KICK)
             {
               /* Hurt if you get hit by kicked laptop: */
               if (!invincible_timer.started())