Changed FloatingScore to support text (changed name to FloatingText). I guess this...
[supertux.git] / src / player.cpp
index f5bfcda..533e761 100644 (file)
@@ -158,7 +158,11 @@ Player::init()
   last_ground_y = 0;
   fall_mode = ON_GROUND;
   jumping = false;
+  flapping = false;
   can_jump = true;
+  can_flap = false;
+  falling_from_flap = false;
+  enable_hover = false;
   butt_jump = false;
   
   frame_main = 0;
@@ -174,6 +178,7 @@ Player::init()
   shooting_timer.init(true);
   growing_timer.init(true);
   idle_timer.init(true);
+  flapping_timer.init(true);
 
   physic.reset();
 }
@@ -314,6 +319,7 @@ Player::action(float elapsed_time)
               physic.set_velocity_y(0);
               jumped_in_solid = true;
               jumping = false;
+              flapping = false;
             }
         }
       else
@@ -373,6 +379,7 @@ Player::action(float elapsed_time)
             {
               /* Make sure jumping is off. */
               jumping = false;
+              flapping = false;
             }
         }
     }
@@ -504,6 +511,7 @@ Player::handle_horizontal_input()
 void
 Player::handle_vertical_input()
 {
+  
   // set fall mode...
   if(on_ground()) {
     fall_mode = ON_GROUND;
@@ -518,8 +526,6 @@ Player::handle_vertical_input()
   // Press jump key
   if(input.up == DOWN && can_jump && on_ground())
     {
-      global_stats.add_points(JUMPS_STAT, 1);
-
       if(duck) { // only jump a little bit when in duck mode {
         physic.set_velocity_y(3);
       } else {
@@ -532,19 +538,56 @@ Player::handle_vertical_input()
 
       --base.y;
       jumping = true;
+      flapping = false;
       can_jump = false;
+      can_flap = false;
       if (size == SMALL)
         SoundManager::get()->play_sound(IDToSound(SND_JUMP));
       else
         SoundManager::get()->play_sound(IDToSound(SND_BIGJUMP));
     }
   // Let go of jump key
-  else if(input.up == UP && jumping && physic.get_velocity_y() > 0)
+  else if(input.up == UP)
     {
-      jumping = false;
-      physic.set_velocity_y(0);
+      if (!flapping && !duck && !falling_from_flap && !on_ground())
+         {
+            can_flap = true;
+         }
+      if (jumping && physic.get_velocity_y() > 0)
+         {
+            jumping = false;
+            physic.set_velocity_y(0);
+         }
     }
 
+   // Flapping
+   if (input.up == DOWN && can_flap)
+     {
+         if (!flapping_timer.started())
+            {
+               flapping_timer.start(TUX_FLAPPING_TIME);
+            }
+         if (!flapping_timer.check()) 
+            {
+               can_flap = false;
+               falling_from_flap = true;
+            }
+         jumping = true;
+         flapping = true;
+         if (flapping_timer.get_gone() <= TUX_FLAPPING_TIME)
+            {
+               physic.set_velocity_y((float)flapping_timer.get_gone()/450);
+            }
+     }
+   
+   // Hover
+   //(disabled by default, use cheat code "hover" to toggle on/off)
+   //TODO: needs some tweaking, especially when used together with double jump and jumping off badguys
+   if (enable_hover && input.up == DOWN && !jumping && !butt_jump && physic.get_velocity_y() <= 0)
+      {
+         physic.set_velocity_y(-1);
+      }
+
    /* In case the player has pressed Down while in a certain range of air,
       enable butt jump action */
   if (input.down == DOWN && !butt_jump && !duck)
@@ -607,7 +650,12 @@ Player::handle_vertical_input()
     }
 
   if(on_ground())   /* Make sure jumping is off. */
-    jumping = false;
+    {
+      jumping = false;
+      flapping = false;
+      falling_from_flap = false;
+      if (flapping_timer.started()) {flapping_timer.stop();}
+    }
 
   input.old_up = input.up;
 }
@@ -1105,6 +1153,10 @@ Player::check_bounds(Camera* camera)
 void
 Player::bounce(BadGuy* badguy)
 {
+  //Make sure we stopped flapping
+  flapping = false;
+  falling_from_flap = false;
+
   if (input.up)
     physic.set_velocity_y(5.2);
   else