Avoid crashing when trying to access info file.
[supertux.git] / src / player.cpp
index f382eff..f84fd03 100644 (file)
@@ -168,6 +168,8 @@ Player::init()
   enable_hover = false;
   butt_jump = false;
   
+  flapping_velocity = 0;
+  
   frame_main = 0;
   frame_ = 0;
 
@@ -584,21 +586,24 @@ Player::handle_vertical_input()
          if (!flapping_timer.started())
             {
                flapping_timer.start(TUX_FLAPPING_TIME);
+               flapping_velocity = physic.get_velocity_x();
             }
          if (!flapping_timer.check()) 
             {
                can_flap = false;
                falling_from_flap = true;
             }
-         //TODO: The slowing down of Tux should be handled...
-         if (physic.get_velocity_x() > 0) {physic.set_velocity_x(WALK_SPEED);}
-         else if (physic.get_velocity_x() < 0) {physic.set_velocity_x(WALK_SPEED * (-1));}
          jumping = true;
          flapping = true;
          if (flapping_timer.get_gone() <= TUX_FLAPPING_TIME)
             {
-               //TODO: ...here, using get_gone to slow him down at an increasing rate
-               physic.set_velocity_y((float)flapping_timer.get_gone()/700);
+               float cv;
+               if (flapping_velocity == 0) {cv = 0;}
+               else {cv = flapping_velocity*(sqrt(TUX_FLAPPING_TIME-(float)flapping_timer.get_gone()))/sqrt(TUX_FLAPPING_TIME);}
+               //Handle change of direction while flapping
+               if (((dir == LEFT) && (cv > 0)) || (dir == RIGHT) && (cv < 0)) {cv *= (-1);}
+               physic.set_velocity_x(cv);
+               physic.set_velocity_y((float)flapping_timer.get_gone()/850);
             }
      }
      
@@ -987,7 +992,7 @@ Player::draw(DrawingContext& context)
   else if (safe_timer.started() && global_frame_counter%2)
     ;  // don't draw Tux
   else
-    tux_body->draw(context, pos, layer, dir == LEFT ? HORIZONTAL_FLIP : NONE_EFFECT);
+    tux_body->draw(context, pos, layer);
 
   // Draw blinking star overlay
   if (invincible_timer.started() &&