Tweaked the backflip timer so that Tux cannot cancel backflip after an arbitrarily...
[supertux.git] / src / object / player.cpp
index 89984f5..0fc1053 100644 (file)
@@ -74,7 +74,7 @@ static const float MAX_WALK_XM = 230;
 /** maximum run velocity (pixel/s) */
 static const float MAX_RUN_XM = 320;
 /** maximum horizontal climb velocity */
-static const float MAX_CLIMB_XM = 48;
+static const float MAX_CLIMB_XM = 96;
 /** maximum vertical climb velocity */
 static const float MAX_CLIMB_YM = 128;
 /** instant velocity when tux starts to walk */
@@ -384,7 +384,7 @@ Player::update(float elapsed_time)
   // check if we landed
   if(on_ground()) {
     jumping = false;
-    if (backflipping && (!backflip_timer.started())) {
+    if (backflipping && (backflip_timer.get_timegone() > 0.15f)) {
       backflipping = false;
       backflip_direction = 0;
 
@@ -435,6 +435,14 @@ Player::update(float elapsed_time)
     if (sprite->animation_done()) growing = false;
   }
 
+  // when climbing animate only while moving
+  if(climbing){
+    if((physic.get_velocity_x()==0)&&(physic.get_velocity_y()==0))
+      sprite->stop_animation();
+    else
+      sprite->set_animation_loops(-1);
+  }
+
 }
 
 bool
@@ -628,7 +636,7 @@ Player::do_backflip() {
   backflipping = true;
   do_jump(-580);
   sound_manager->play("sounds/flip.wav");
-  backflip_timer.start(0.15f);
+  backflip_timer.start(TUX_BACKFLIP_TIME);
 }
 
 void
@@ -808,7 +816,7 @@ Player::handle_input()
         dest.p1.x = bbox.get_right() + 1;
         dest.p2.x = dest.p1.x + grabbed_bbox.get_width();
       }
-      if(Sector::current()->is_free_of_movingstatics(dest)) {
+      if(Sector::current()->is_free_of_tiles(dest, true)) {
         moving_object->set_pos(dest.p1);
         if(controller->hold(Controller::UP)) {
           grabbed_object->ungrab(*this, UP);
@@ -821,6 +829,12 @@ Player::handle_input()
       log_debug << "Non MovingObject grabbed?!?" << std::endl;
     }
   }
+
+  /* stop backflipping at will */
+  if( backflipping && ( !controller->hold(Controller::JUMP) && !backflip_timer.started()) ){
+    backflipping = false;
+    backflip_direction = 0;
+  }
 }
 
 void
@@ -966,7 +980,7 @@ Player::set_bonus(BonusType type, bool animate)
 {
   if((player_status->bonus == NO_BONUS) && (type != NO_BONUS)) {
     if (!adjust_height(BIG_TUX_HEIGHT)) {
-      printf("can't adjust\n");
+      log_debug << "Can't adjust Tux height" << std::endl;
       return false;
     }
     if(animate) {
@@ -1307,6 +1321,21 @@ Player::kill(bool completely)
       return;
     }
 
+    if (player_status->coins >= 25 && !GameSession::current()->get_reset_point_sectorname().empty())
+    {
+      for (int i = 0; i < 5; i++)
+      {
+        // the numbers: starting x, starting y, velocity y
+        Sector::current()->add_object(new FallingCoin(get_pos() +
+                                                      Vector(graphicsRandom.rand(5), graphicsRandom.rand(-32,18)),
+                                                      graphicsRandom.rand(-100,100)));
+      }
+      player_status->coins -= std::max(player_status->coins/10, 25);
+    }
+    else
+    {
+      GameSession::current()->set_reset_point("", Vector());
+    }
     physic.enable_gravity(true);
     physic.set_gravity_modifier(1.0f); // Undo jump_early_apex
     safe_timer.stop();
@@ -1457,12 +1486,16 @@ Player::set_edit_mode(bool enable)
 void 
 Player::start_climbing(Climbable& climbable)
 {
-  if (climbing == &climbable) return;
+  if (climbing || !&climbable) return;
 
   climbing = &climbable;
   physic.enable_gravity(false);
   physic.set_velocity(0, 0);
   physic.set_acceleration(0, 0);
+  if (backflipping) {
+    backflipping = false;
+    backflip_direction = 0;
+  }
 }
 
 void