X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fplayer.cpp;h=033f569b257867093b025bf6e686cde71e8789e8;hb=555d1b7bebb45326d82d934e07463209837309b0;hp=6e9245fe79e48043686303d29fa675cd572d5222;hpb=a736c03b5f336300daad0a356e23e86213b5413b;p=supertux.git diff --git a/src/object/player.cpp b/src/object/player.cpp index 6e9245fe7..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: */ @@ -949,6 +953,8 @@ Player::draw(DrawingContext& context) } std::string sa_prefix = ""; + std::string sa_postfix = ""; + if (player_status->bonus == GROWUP_BONUS) sa_prefix = "big"; else if (player_status->bonus == FIRE_BONUS) @@ -958,36 +964,41 @@ Player::draw(DrawingContext& context) else sa_prefix = "small"; + if(dir == LEFT) + sa_postfix = "-left"; + else + sa_postfix = "-right"; + /* Set Tux sprite action */ if(dying) { sprite->set_action("gameover"); } else if (growing) { - sprite->set_action_continued((dir == LEFT)?"grow-left":"grow-right"); + sprite->set_action_continued("grow"+sa_postfix); // while growing, do not change action // do_duck() will take care of cancelling growing manually // update() will take care of cancelling when growing completed } else if (climbing) { - sprite->set_action(sa_prefix+((dir == LEFT)?"-skid-left":"-skid-right")); + sprite->set_action(sa_prefix+"-skid"+sa_postfix); } else if (backflipping) { - sprite->set_action(sa_prefix+((dir == LEFT)?"-backflip-left":"-backflip-right")); + sprite->set_action(sa_prefix+"-backflip"+sa_postfix); } else if (duck && is_big()) { - sprite->set_action(sa_prefix+((dir == LEFT)?"-duck-left":"-duck-right")); + sprite->set_action(sa_prefix+"-duck"+sa_postfix); } else if (skidding_timer.started() && !skidding_timer.check()) { - sprite->set_action(sa_prefix+((dir == LEFT)?"-skid-left":"-skid-right")); + sprite->set_action(sa_prefix+"-skid"+sa_postfix); } else if (kick_timer.started() && !kick_timer.check()) { - sprite->set_action(sa_prefix+((dir == LEFT)?"-kick-left":"-kick-right")); + sprite->set_action(sa_prefix+"-kick"+sa_postfix); } else if ((wants_buttjump || does_buttjump) && is_big()) { - sprite->set_action(sa_prefix+((dir == LEFT)?"-buttjump-left":"-buttjump-right")); + sprite->set_action(sa_prefix+"-buttjump"+sa_postfix); } else if (!on_ground()) { - sprite->set_action(sa_prefix+((dir == LEFT)?"-jump-left":"-jump-right")); + sprite->set_action(sa_prefix+"-jump"+sa_postfix); } else { if (fabsf(physic.get_velocity_x()) < 1.0f) { @@ -996,7 +1007,7 @@ Player::draw(DrawingContext& context) idle_stage = 0; idle_timer.start(IDLE_TIME[idle_stage]/1000.0f); - sprite->set_action_continued(sa_prefix+((dir == LEFT)?"-" + IDLE_STAGES[idle_stage] + "-left":"-" + IDLE_STAGES[idle_stage] + "-right")); + sprite->set_action_continued(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix); } else if (idle_timer.check() || (IDLE_TIME[idle_stage] == 0 && sprite->animation_done())) { idle_stage++; @@ -1006,13 +1017,16 @@ Player::draw(DrawingContext& context) idle_timer.start(IDLE_TIME[idle_stage]/1000.0f); if (IDLE_TIME[idle_stage] == 0) - sprite->set_action(sa_prefix+((dir == LEFT)?"-" + IDLE_STAGES[idle_stage] + "-left":"-" + IDLE_STAGES[idle_stage] + "-right"), 1); + sprite->set_action(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix, 1); else - sprite->set_action(sa_prefix+((dir == LEFT)?"-" + IDLE_STAGES[idle_stage] + "-left":"-" + IDLE_STAGES[idle_stage] + "-right")); + sprite->set_action(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix); + } + else { + sprite->set_action_continued(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix); } } else { - sprite->set_action(sa_prefix+((dir == LEFT)?"-walk-left":"-walk-right")); + sprite->set_action(sa_prefix+"-walk"+sa_postfix); } }