Changed jump behaviour: Tux will now jump even if the button was pressed (up to)...
authorChristoph Sommer <mail@christoph-sommer.de>
Sat, 6 Sep 2008 20:35:45 +0000 (20:35 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Sat, 6 Sep 2008 20:35:45 +0000 (20:35 +0000)
SVN-Revision: 5764

src/object/player.cpp
src/object/player.hpp

index 0cc997c..033f569 100644 (file)
@@ -105,6 +105,8 @@ namespace {
       the apex of the jump is reached */
   static const float JUMP_EARLY_APEX_FACTOR = 3.0;
 
+  static const float JUMP_GRACE_TIME = 0.25f; /**< time before hitting the ground that the jump button may be pressed (and still trigger a jump) */
+
   bool no_water = true;
 }
 
@@ -608,7 +610,9 @@ void
 Player::handle_vertical_input()
 {
   // Press jump key
-  if(controller->pressed(Controller::JUMP) && (can_jump)) {
+  if(controller->pressed(Controller::JUMP)) jump_button_timer.start(JUMP_GRACE_TIME);
+  if(controller->hold(Controller::JUMP) && jump_button_timer.started() && can_jump) {
+    jump_button_timer.stop();
     if (duck) {
       // when running, only jump a little bit; else do a backflip
       if ((physic.get_velocity_x() != 0) || (controller->hold(Controller::LEFT)) || (controller->hold(Controller::RIGHT))) do_jump(-300); else do_backflip();
@@ -696,7 +700,7 @@ Player::handle_input()
   if (!backflipping) handle_horizontal_input();
 
   /* Jump/jumping? */
-  if (on_ground() && !controller->hold(Controller::JUMP))
+  if (on_ground())
     can_jump = true;
 
   /* Handle vertical movement: */
index d76d21a..91a1fcf 100644 (file)
@@ -86,6 +86,7 @@ public:
   bool on_ground_flag;
   bool jumping;
   bool can_jump;
+  Timer jump_button_timer; /**< started when player presses the jump button; runs until Tux jumps or JUMP_GRACE_TIME runs out */
   bool wants_buttjump;
   bool does_buttjump;