From 555d1b7bebb45326d82d934e07463209837309b0 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Sat, 6 Sep 2008 20:35:45 +0000 Subject: [PATCH] Changed jump behaviour: Tux will now jump even if the button was pressed (up to) 250ms early SVN-Revision: 5764 --- src/object/player.cpp | 8 ++++++-- src/object/player.hpp | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/object/player.cpp b/src/object/player.cpp index 0cc997cfe..033f569b2 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -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: */ diff --git a/src/object/player.hpp b/src/object/player.hpp index d76d21ac2..91a1fcfc5 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -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; -- 2.11.0