From: Wolfgang Becker Date: Sun, 9 Jul 2006 23:38:24 +0000 (+0000) Subject: Made Snail and Mr.Tree change direction only once per active_update. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5b6a79df7b102dba6322bc923ece8c572ea56775;p=supertux.git Made Snail and Mr.Tree change direction only once per active_update. Riding down a moving platform still lokes strange; Mr.Tree walks uphill, but not down again. SVN-Revision: 3973 --- diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index 9c4a0fa60..0e7970b9c 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -39,6 +39,7 @@ 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 @@ -75,13 +76,15 @@ 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 (might_fall()) + if (might_fall() && !recently_changed_direction ) { + recently_changed_direction = true; dir = (dir == LEFT ? RIGHT : LEFT); activate(); } @@ -177,6 +180,8 @@ 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(); } @@ -186,6 +191,8 @@ HitResponse MrTree::collision_badguy(BadGuy& , const CollisionHit& hit) { if(hit.left || hit.right) { + if( recently_changed_direction ) return CONTINUE; + recently_changed_direction = true; dir = dir == LEFT ? RIGHT : LEFT; activate(); } diff --git a/src/badguy/mrtree.hpp b/src/badguy/mrtree.hpp index 02a433d83..9d99187de 100644 --- a/src/badguy/mrtree.hpp +++ b/src/badguy/mrtree.hpp @@ -42,8 +42,12 @@ protected: MyState mystate; 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 5df4e0e68..bc00a4f40 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -35,6 +35,7 @@ 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) @@ -43,6 +44,7 @@ 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 @@ -102,13 +104,16 @@ Snail::be_kicked() void Snail::active_update(float elapsed_time) { + recently_changed_direction = false; switch (state) { case STATE_NORMAL: if (might_fall(601)) { - dir = (dir == LEFT ? RIGHT : LEFT); - sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(-physic.get_velocity_x()); + 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()); } break; @@ -159,6 +164,8 @@ 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()); @@ -184,7 +191,8 @@ 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"); @@ -202,6 +210,8 @@ 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"); physic.set_velocity_x(-physic.get_velocity_x()); diff --git a/src/badguy/snail.hpp b/src/badguy/snail.hpp index 35802b022..3f56e227d 100644 --- a/src/badguy/snail.hpp +++ b/src/badguy/snail.hpp @@ -57,6 +57,7 @@ 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