Do not rotate sprite when we are dying
[supertux.git] / src / object / player.cpp
index 89984f5..c833a20 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 */
@@ -213,6 +213,7 @@ Player::init()
   deactivated = false;
   backflipping = false;
   backflip_direction = 0;
+  sprite->set_angle(0.0f);
   visible = true;
   swimming = false;
   on_ice = false;
@@ -323,6 +324,7 @@ Player::trigger_sequence(std::string sequence_name)
   if (climbing) stop_climbing(*climbing);
   backflipping = false;
   backflip_direction = 0;
+  sprite->set_angle(0.0f);
   GameSession::current()->start_sequence(sequence_name);
 }
 
@@ -335,6 +337,7 @@ Player::update(float elapsed_time)
   no_water = true;
 
   if(dying && dying_timer.check()) {
+    set_bonus(NO_BONUS, true);
     dead = true;
     return;
   }
@@ -355,7 +358,7 @@ Player::update(float elapsed_time)
   }
 
   // on downward slopes, adjust vertical velocity so tux walks smoothly down
-  if (on_ground()) {
+  if (on_ground() && !dying) {
     if(floor_normal.y != 0) {
       if ((floor_normal.x * physic.get_velocity_x()) >= 0) {
         physic.set_velocity_y(250);
@@ -364,10 +367,12 @@ Player::update(float elapsed_time)
   }
 
   // handle backflipping
-  if (backflipping) {
+  if (backflipping && !dying) {
     //prevent player from changing direction when backflipping
     dir = (backflip_direction == 1) ? LEFT : RIGHT;
     if (backflip_timer.started()) physic.set_velocity_x(100 * backflip_direction);
+    //rotate sprite during flip
+    sprite->set_angle(sprite->get_angle() + (dir==LEFT?1:-1) * elapsed_time * (360.0f / 0.5f));
   }
 
   // set fall mode...
@@ -384,9 +389,10 @@ 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;
+      sprite->set_angle(0.0f);
 
       // if controls are currently deactivated, we take care of standing up ourselves
       if (deactivated)
@@ -435,6 +441,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 +642,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 +822,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 +835,13 @@ 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;
+    sprite->set_angle(0.0f);
+  }
 }
 
 void
@@ -966,7 +987,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) {
@@ -1090,8 +1111,10 @@ Player::draw(DrawingContext& context)
   else if ((wants_buttjump || does_buttjump) && is_big()) {
     sprite->set_action(sa_prefix+"-buttjump"+sa_postfix);
   }
-  else if (!on_ground()) {
-    sprite->set_action(sa_prefix+"-jump"+sa_postfix);
+  else if (!on_ground() || fall_mode != ON_GROUND) {
+    if(physic.get_velocity_x() != 0 || fall_mode != ON_GROUND) {
+        sprite->set_action(sa_prefix+"-jump"+sa_postfix);
+    }
   }
   else {
     if (fabsf(physic.get_velocity_x()) < 1.0f) {
@@ -1292,6 +1315,7 @@ Player::kill(bool completely)
       adjust_height(SMALL_TUX_HEIGHT);
       duck = false;
       backflipping = false;
+      sprite->set_angle(0.0f);
       set_bonus(NO_BONUS, true);
     } else if(player_status->bonus == NO_BONUS) {
       safe_timer.start(TUX_SAFE_TIME);
@@ -1307,6 +1331,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();
@@ -1336,6 +1375,7 @@ Player::move(const Vector& vector)
     set_size(TUX_WIDTH, SMALL_TUX_HEIGHT);
   duck = false;
   backflipping = false;
+  sprite->set_angle(0.0f);
   last_ground_y = vector.y;
   if (climbing) stop_climbing(*climbing);
 
@@ -1457,12 +1497,17 @@ 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;
+    sprite->set_angle(0.0f);
+  }
 }
 
 void