From 803e500c210ad5cd60991ba7eb774a6405587e8f Mon Sep 17 00:00:00 2001 From: mathnerd314 Date: Mon, 25 Jan 2010 22:55:44 +0000 Subject: [PATCH] MrIceBlock stops after bouncing a lot. Snail can be kicked. Player backflip/duck jump behavior change. git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6272 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/badguy/mriceblock.cpp | 14 +++++++------- src/badguy/snail.cpp | 34 +++++++++++++++++++++++++++------- src/badguy/snail.hpp | 1 + src/object/player.cpp | 11 +++-------- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index 4b8d6e332..eed83fed7 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -21,6 +21,8 @@ #include "sprite/sprite.hpp" #include "supertux/object_factory.hpp" +#include + namespace { const float KICKSPEED = 500; const int MAXSQUISHES = 10; @@ -102,16 +104,14 @@ MrIceBlock::collision_solid(const CollisionHit& hit) WalkingBadguy::collision_solid(hit); break; case ICESTATE_KICKED: { - if(hit.right && dir == RIGHT) { - dir = LEFT; - sound_manager->play("sounds/iceblock_bump.wav", get_pos()); - physic.set_velocity_x(-KICKSPEED); - } else if(hit.left && dir == LEFT) { - dir = RIGHT; + if((hit.right && dir == RIGHT) || (hit.left && dir == LEFT)) { + dir = (dir == LEFT) ? RIGHT : LEFT; sound_manager->play("sounds/iceblock_bump.wav", get_pos()); - physic.set_velocity_x(KICKSPEED); + physic.set_velocity_x(-physic.get_velocity_x()*.975); } sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); + if(fabsf(physic.get_velocity_x()) < walk_speed*1.5) + set_state(ICESTATE_NORMAL); break; } case ICESTATE_FLAT: diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index c441b0158..faf86602f 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -87,7 +87,7 @@ Snail::be_kicked() state = STATE_KICKED_DELAY; sprite->set_action(dir == LEFT ? "flat-left" : "flat-right", 1); - physic.set_velocity_x(0); + physic.set_velocity_x(dir == LEFT ? -SNAIL_KICK_SPEED : SNAIL_KICK_SPEED); physic.set_velocity_y(0); // start a timer to delay addition of upward movement until we are (hopefully) out from under the player @@ -182,6 +182,24 @@ Snail::collision_badguy(BadGuy& badguy, const CollisionHit& hit) return ABORT_MOVE; } +HitResponse +Snail::collision_player(Player& player, const CollisionHit& hit) +{ + // handle kicks from left or right side + if(state == STATE_FLAT && (hit.left || hit.right)) { + if(hit.left) { + dir = RIGHT; + } else if(hit.right) { + dir = LEFT; + } + player.kick(); + be_kicked(); + return FORCE_MOVE; + } + + return BadGuy::collision_player(player, hit); +} + bool Snail::collision_squished(GameObject& object) { @@ -196,17 +214,19 @@ Snail::collision_squished(GameObject& object) case STATE_KICKED: case STATE_NORMAL: - { + + // Can't stomp in midair + if(!on_ground()) + break; + squishcount++; if (squishcount >= MAX_SNAIL_SQUISHES) { kill_fall(); return true; } - } - - sound_manager->play("sounds/stomp.wav", get_pos()); - be_flat(); - break; + sound_manager->play("sounds/stomp.wav", get_pos()); + be_flat(); + break; case STATE_FLAT: sound_manager->play("sounds/kick.wav", get_pos()); diff --git a/src/badguy/snail.hpp b/src/badguy/snail.hpp index 9b482d334..40181b9d5 100644 --- a/src/badguy/snail.hpp +++ b/src/badguy/snail.hpp @@ -31,6 +31,7 @@ public: void initialize(); void collision_solid(const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); + HitResponse collision_player(Player& player, const CollisionHit& hit); bool can_break(); void active_update(float elapsed_time); diff --git a/src/object/player.cpp b/src/object/player.cpp index 1f3b0cd02..8c830bfa7 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -658,15 +658,10 @@ Player::handle_vertical_input() 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))) - { + // jump a little bit if moving in same direction; otherwise, do a backflip + if ((physic.get_velocity_x() < 0 && dir == LEFT) || (physic.get_velocity_x() > 0 && dir == RIGHT)) { do_jump(-300); - } - else - { + } else { do_backflip(); } } else { -- 2.11.0