From: Wolfgang Becker Date: Mon, 10 Jul 2006 15:45:40 +0000 (+0000) Subject: Tree, snail: only turn around when hit from front. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b71c1bff3c89c0b56cf589da078d7d3815a6f4d5;p=supertux.git Tree, snail: only turn around when hit from front. SVN-Revision: 3979 --- diff --git a/data/levels/world2/fish.stl b/data/levels/world2/fish.stl index ce9e28374..9e4d99949 100644 --- a/data/levels/world2/fish.stl +++ b/data/levels/world2/fish.stl @@ -21,6 +21,12 @@ (y 705.2742) (sprite "") ) + (mrbomb + (direction "auto") + (x 3200) + (y 736) + (sprite "") + ) (fish (x 2400) (y 736) @@ -95,11 +101,6 @@ (x 992) (y 736) ) - (snail - (direction "auto") - (x 3168) - (y 768) - ) (dispenser (badguy "poisonivy") (cycle 3) diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index ed0d6d495..497f5005c 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -39,7 +39,6 @@ MrTree::MrTree(const lisp::Lisp& reader) sprite->set_action(dir == LEFT ? "large-left" : "large-right"); sound_manager->preload("sounds/mr_tree.ogg"); sound_manager->preload("sounds/mr_treehit.ogg"); - recently_changed_direction = false; } void @@ -76,15 +75,13 @@ MrTree::activate() void MrTree::active_update(float elapsed_time) { - recently_changed_direction = false; if ((mystate == STATE_INVINCIBLE) && (invincible_timer.check())) { mystate = STATE_NORMAL; activate(); } - if (on_ground() && might_fall() && !recently_changed_direction ) + if (on_ground() && might_fall()) { - recently_changed_direction = true; dir = (dir == LEFT ? RIGHT : LEFT); activate(); } @@ -182,19 +179,17 @@ MrTree::collision_solid(const CollisionHit& hit) if(hit.top || hit.bottom) { physic.set_velocity_y(0); } else { - if( recently_changed_direction ) return; - recently_changed_direction = true; - dir = dir == LEFT ? RIGHT : LEFT; - activate(); + if( ( hit.left && dir == LEFT )|| (hit.right && dir == RIGHT ) ){ + dir = dir == LEFT ? RIGHT : LEFT; + activate(); + } } } HitResponse MrTree::collision_badguy(BadGuy& , const CollisionHit& hit) { - if(hit.left || hit.right) { - if( recently_changed_direction ) return CONTINUE; - recently_changed_direction = true; + if( ( hit.left && dir == LEFT )|| (hit.right && dir == RIGHT ) ){ dir = dir == LEFT ? RIGHT : LEFT; activate(); } diff --git a/src/badguy/mrtree.hpp b/src/badguy/mrtree.hpp index 9d99187de..5b2641d82 100644 --- a/src/badguy/mrtree.hpp +++ b/src/badguy/mrtree.hpp @@ -44,10 +44,6 @@ protected: Timer invincible_timer; bool collision_squished(Player& player); - -private: - bool recently_changed_direction; - }; #endif diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index 0de7bfaab..fd8819f42 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -35,7 +35,6 @@ Snail::Snail(const lisp::Lisp& reader) sound_manager->preload("sounds/iceblock_bump.wav"); sound_manager->preload("sounds/stomp.wav"); sound_manager->preload("sounds/kick.wav"); - recently_changed_direction = false; } Snail::Snail(const Vector& pos, Direction d) @@ -44,7 +43,6 @@ Snail::Snail(const Vector& pos, Direction d) sound_manager->preload("sounds/iceblock_bump.wav"); sound_manager->preload("sounds/stomp.wav"); sound_manager->preload("sounds/kick.wav"); - recently_changed_direction = false; } void @@ -104,13 +102,10 @@ Snail::be_kicked() void Snail::active_update(float elapsed_time) { - recently_changed_direction = false; switch (state) { case STATE_NORMAL: if (on_ground() && might_fall(601)) { - if( recently_changed_direction ) break; - recently_changed_direction = true; dir = (dir == LEFT ? RIGHT : LEFT); sprite->set_action(dir == LEFT ? "left" : "right"); physic.set_velocity_x(-physic.get_velocity_x()); @@ -166,11 +161,11 @@ Snail::collision_solid(const CollisionHit& hit) switch(state) { case STATE_NORMAL: - if( recently_changed_direction ) break; - recently_changed_direction = true; - dir = dir == LEFT ? RIGHT : LEFT; - sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(-physic.get_velocity_x()); + if( (dir == LEFT && hit.left) || ( dir == RIGHT && hit.right) ){ + dir = dir == LEFT ? RIGHT : LEFT; + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } break; case STATE_FLAT: @@ -193,13 +188,13 @@ Snail::collision_solid(const CollisionHit& hit) brick->try_break(); } #endif - if( recently_changed_direction ) break; - recently_changed_direction = true; - dir = (dir == LEFT) ? RIGHT : LEFT; - sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); + if( ( dir == LEFT && hit.left ) || ( dir == RIGHT && hit.right) ){ + dir = (dir == LEFT) ? RIGHT : LEFT; + sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); - physic.set_velocity_x(-physic.get_velocity_x()*0.75); - if (fabsf(physic.get_velocity_x()) < WALKSPEED) be_normal(); + physic.set_velocity_x(-physic.get_velocity_x()*0.75); + if (fabsf(physic.get_velocity_x()) < WALKSPEED) be_normal(); + } break; } @@ -211,11 +206,14 @@ Snail::collision_badguy(BadGuy& badguy, const CollisionHit& hit) { switch(state) { case STATE_NORMAL: - if(hit.left || hit.right) { - if( recently_changed_direction ) return CONTINUE; - recently_changed_direction = true; - dir = (dir == LEFT) ? RIGHT : LEFT; - sprite->set_action(dir == LEFT ? "left" : "right"); + // printf("Snail <-> Badguy %s %s %s %s %s\n", hit.left?"left":"", hit.right?"right":"", hit.top?"top":"", hit.bottom?"bottom":"", hit.crush?"crush":""); + if( hit.left && dir == LEFT ){ + dir = RIGHT; + sprite->set_action( "right" ); + physic.set_velocity_x(-physic.get_velocity_x()); + } else if( hit.right && dir == RIGHT ){ + dir = LEFT; + sprite->set_action( "left" ); physic.set_velocity_x(-physic.get_velocity_x()); } return CONTINUE; diff --git a/src/badguy/snail.hpp b/src/badguy/snail.hpp index 3f56e227d..35802b022 100644 --- a/src/badguy/snail.hpp +++ b/src/badguy/snail.hpp @@ -57,7 +57,6 @@ private: Timer flat_timer; /**< wait time until flipping right-side-up again */ Timer kicked_delay_timer; /**< wait time until switching from STATE_KICKED_DELAY to STATE_KICKED */ int squishcount; - bool recently_changed_direction; }; #endif