From: Ingo Ruhnke Date: Fri, 14 Mar 2008 23:48:23 +0000 (+0000) Subject: Ed 's jump patch X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1d01d271889c13653bffd0c9824ee8a72b339b56;p=supertux.git Ed 's jump patch - minimum jump high is now ~2 tiles - small jumps look smoother - should change nothing for bigger jump, so for normal gameplay it should feel the same (unless there are unknown bugs) SVN-Revision: 5375 --- diff --git a/src/object/player.cpp b/src/object/player.cpp index df0a5aa43..e4bbced9a 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -86,6 +86,9 @@ static const float CHEER_TIME = 1.0f; /** if Tux cannot unduck for this long, he will get hurt */ static const float UNDUCK_HURT_TIME = 0.25f; +/** gravity is higher after the jump key is released before + the apex of the jump is reached */ +static const float JUMP_EARLY_APEX_FACTOR = 3.0; namespace{ bool no_water = true; @@ -140,6 +143,7 @@ Player::init() last_ground_y = 0; fall_mode = ON_GROUND; jumping = false; + jump_early_apex = false; can_jump = true; wants_buttjump = false; does_buttjump = false; @@ -567,6 +571,24 @@ Player::do_jump(float yspeed) { } void +Player::early_jump_apex() { + if(jump_early_apex) { + return; + } + jump_early_apex = true; + physic.set_gravity(physic.get_gravity() * JUMP_EARLY_APEX_FACTOR); +}; + +void +Player::do_jump_apex() { + if(!jump_early_apex) { + return; + } + jump_early_apex = false; + physic.set_gravity(physic.get_gravity() / JUMP_EARLY_APEX_FACTOR); +} + +void Player::handle_vertical_input() { // Press jump key @@ -583,10 +605,14 @@ Player::handle_vertical_input() else if(!controller->hold(Controller::JUMP)) { if (!backflipping && jumping && physic.get_velocity_y() < 0) { jumping = false; - physic.set_velocity_y(0); + early_jump_apex(); } } + if(jump_early_apex && physic.get_velocity_y() >= 0) { + do_jump_apex(); + } + /* In case the player has pressed Down while in a certain range of air, enable butt jump action */ if (controller->hold(Controller::DOWN) && !duck && is_big() && !on_ground()) { diff --git a/src/object/player.hpp b/src/object/player.hpp index 4c715c79e..be124ac05 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -74,6 +74,7 @@ private: bool swimming; float speedlimit; Controller* scripting_controller_old; /**< Saves the old controller while the scripting_controller is used */ + bool jump_early_apex; public: Direction dir; @@ -273,6 +274,9 @@ private: void deactivate(); void walk(float speed); + void do_jump_apex(); + void early_jump_apex(); + /** * slows Tux down a little, based on where he's standing */