X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fplayer.cpp;h=afc4eb5e078232cd59033ee104e21c43118c7809;hb=54769dff40025a2e798d2544df6d745196968f94;hp=8e50c7e4f27240a91b1ad2df513b01b1edbbcddc;hpb=fcf9a94afe527884758b66ffc314dbb5b8b20c09;p=supertux.git diff --git a/src/player.cpp b/src/player.cpp index 8e50c7e4f..afc4eb5e0 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -92,6 +92,7 @@ Player::init() skidding_timer.init(true); safe_timer.init(true); frame_timer.init(true); + kick_timer.init(true); physic.reset(); } @@ -121,6 +122,8 @@ Player::key_event(SDLKey key, int state) } else if(key == keymap.fire) { + if (state == UP) + input.old_fire = UP; input.fire = state; return true; } @@ -262,6 +265,7 @@ Player::action(double frame_ratio) skidding_timer.check(); invincible_timer.check(); safe_timer.check(); + kick_timer.check(); } bool @@ -367,7 +371,7 @@ Player::handle_horizontal_input() void Player::handle_vertical_input() { - if(input.up == DOWN) + if(input.up == DOWN && input.old_up == UP) { if (on_ground()) { @@ -406,12 +410,14 @@ Player::handle_input() { handle_vertical_input(); } + input.old_up = input.up; /* Shoot! */ if (input.fire == DOWN && input.old_fire == UP && got_coffee) { World::current()->add_bullet(base.x, base.y, physic.get_velocity_x(), dir); + input.old_fire = DOWN; } /* tux animations: */ @@ -437,7 +443,7 @@ Player::handle_input() } /* Duck! */ - if (input.down == DOWN && size == BIG && !duck && physic.get_velocity_y() == 0) + if (input.down == DOWN && size == BIG && !duck && physic.get_velocity_y() == 0 && on_ground()) { duck = true; base.height = 32; @@ -450,11 +456,25 @@ Player::handle_input() duck = false; base.y -= 32; base.height = 64; - old_base = previous_base = base; + // changing base size confuses collision otherwise + old_base = previous_base = base; } } void +Player::grow() +{ + if(size == BIG) + return; + + size = BIG; + base.height = 64; + base.y -= 32; + + old_base = previous_base = base; +} + +void Player::grabdistros() { /* Grab distros: */ @@ -505,48 +525,52 @@ Player::draw() else sprite = &largetux; - if (skidding_timer.started()) + if (duck && size != SMALL) + { + if (dir == RIGHT) + sprite->duck_right->draw(base.x - scroll_x, base.y); + else + sprite->duck_left->draw(base.x - scroll_x, base.y); + } + else if (skidding_timer.started()) { if (dir == RIGHT) sprite->skid_right->draw(base.x - scroll_x, base.y); else sprite->skid_left->draw(base.x - scroll_x, base.y); } + else if (kick_timer.started()) + { + if (dir == RIGHT) + sprite->kick_right->draw(base.x - scroll_x, base.y); + else + sprite->kick_left->draw(base.x - scroll_x, base.y); + } + else if (physic.get_velocity_y() != 0) + { + if (dir == RIGHT) + sprite->jump_right->draw(base.x - scroll_x, base.y); + else + sprite->jump_left->draw(base.x - scroll_x, base.y); + } else { - if (duck) + if (fabsf(physic.get_velocity_x()) < 1.0f) // standing { if (dir == RIGHT) - sprite->duck_right->draw(base.x - scroll_x, base.y); - else - sprite->duck_left->draw(base.x - scroll_x, base.y); - } - else if (physic.get_velocity_y() != 0) - { - if (dir == RIGHT) - sprite->jump_right->draw(base.x - scroll_x, base.y); + sprite->stand_right->draw( base.x - scroll_x, base.y); else - sprite->jump_left->draw(base.x - scroll_x, base.y); + sprite->stand_left->draw( base.x - scroll_x, base.y); } - else + else // moving { - if (fabsf(physic.get_velocity_x()) < 1.0f) // standing - { - if (dir == RIGHT) - sprite->stand_right->draw( base.x - scroll_x, base.y); - else - sprite->stand_left->draw( base.x - scroll_x, base.y); - } - else // moving - { - if (dir == RIGHT) - sprite->walk_right->draw(base.x - scroll_x, base.y); - else - sprite->walk_left->draw(base.x - scroll_x, base.y); - } + if (dir == RIGHT) + sprite->walk_right->draw(base.x - scroll_x, base.y); + else + sprite->walk_left->draw(base.x - scroll_x, base.y); } } - + // Draw arm overlay graphics when Tux is holding something if (holding_something && physic.get_velocity_y() == 0) { @@ -587,7 +611,8 @@ Player::collision(void* p_c_object, int c_object) !safe_timer.started() && pbad_c->mode != BadGuy::HELD) { - if (pbad_c->mode == BadGuy::FLAT && input.fire == DOWN) + if (pbad_c->mode == BadGuy::FLAT && input.fire == DOWN + && !holding_something) { holding_something = true; pbad_c->mode = BadGuy::HELD; @@ -621,7 +646,7 @@ Player::collision(void* p_c_object, int c_object) } else { - pbad_c->kill_me(); + pbad_c->kill_me(25); } } player_status.score_multiplier++;