From: Florian Forster Date: Mon, 1 Mar 2010 16:07:21 +0000 (+0000) Subject: object/unstable_tile.[ch]pp: Implement third state, "shake". X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=e480b3e4e611fe77a6d02ec49c88b21458fb4ec0;p=supertux.git object/unstable_tile.[ch]pp: Implement third state, "shake". The order of the states is now: shake → dissolve → fall-down Each state is optional. The tile will be made non-solid at the end of "dissolve". If that action is missing in the sprite, the tile will be solid when it falls down, making it possible to jump off of it. Jumping off of a falling tile works better than I had expected. I've changed the gravity modifier to 0.98 nonetheless, so that the tile falls slightly slower than Tux does. The "unstable_tile" and "castleblock" sprites now use the "shake" action and not the "dissolve" action. SVN-Revision: 6492 --- diff --git a/data/images/objects/unstable_tile/castleblock.sprite b/data/images/objects/unstable_tile/castleblock.sprite index 90670dce4..41a1f9e70 100644 --- a/data/images/objects/unstable_tile/castleblock.sprite +++ b/data/images/objects/unstable_tile/castleblock.sprite @@ -6,7 +6,7 @@ ) ) (action - (name "dissolve") + (name "shake") (fps 8) (images "castleblock-0.png" @@ -15,11 +15,11 @@ "castleblock-3.png" ) ) -; (action -; (name "fall-down") -; (fps 1) -; (images -; "castleblock-3.png" -; ) -; ) + (action + (name "fall-down") + (fps 1) + (images + "castleblock-3.png" + ) + ) ) diff --git a/data/images/objects/unstable_tile/unstable_tile.sprite b/data/images/objects/unstable_tile/unstable_tile.sprite index 8b6a2bddc..14d56a7c9 100644 --- a/data/images/objects/unstable_tile/unstable_tile.sprite +++ b/data/images/objects/unstable_tile/unstable_tile.sprite @@ -6,7 +6,7 @@ ) ) (action - (name "dissolve") + (name "shake") (fps 20) (images "crumbling-0.png" @@ -21,11 +21,11 @@ "crumbling-1.png" ) ) -; (action -; (name "fall-down") -; (fps 1) -; (images -; "normal.png" -; ) -; ) + (action + (name "fall-down") + (fps 1) + (images + "normal.png" + ) + ) ) diff --git a/src/object/unstable_tile.cpp b/src/object/unstable_tile.cpp index 0d69f151c..f83d71614 100644 --- a/src/object/unstable_tile.cpp +++ b/src/object/unstable_tile.cpp @@ -30,6 +30,8 @@ UnstableTile::UnstableTile(const Reader& lisp) : state(STATE_NORMAL) { sprite->set_action("normal"); + physic.set_gravity_modifier (.98); + physic.enable_gravity (false); } HitResponse @@ -39,21 +41,35 @@ UnstableTile::collision(GameObject& other, const CollisionHit& ) Player* player = dynamic_cast (&other); if(player != NULL && player->get_bbox().get_bottom() < get_bbox().get_top() + SHIFT_DELTA) { - dissolve (); + shake (); } if (dynamic_cast (&other)) { - dissolve (); + shake (); } } return FORCE_MOVE; } -void UnstableTile::dissolve (void) +void UnstableTile::shake (void) { if (state != STATE_NORMAL) return; + if (sprite->has_action ("shake")) { + state = STATE_SHAKE; + this->set_action ("shake", /* loops = */ 1); + } + else { + dissolve (); + } +} + +void UnstableTile::dissolve (void) +{ + if ((state != STATE_NORMAL) && (state != STATE_SHAKE)) + return; + if (sprite->has_action ("dissolve")) { state = STATE_DISSOLVE; this->set_action ("dissolve", /* loops = */ 1); @@ -65,13 +81,14 @@ void UnstableTile::dissolve (void) void UnstableTile::fall_down (void) { - if ((state != STATE_NORMAL) && (state != STATE_DISSOLVE)) + if ((state != STATE_NORMAL) + && (state != STATE_SHAKE) + && (state != STATE_DISSOLVE)) return; if (sprite->has_action ("fall-down")) { state = STATE_FALL; this->set_action ("fall-down", /* loops = */ 1); - set_group (COLGROUP_DISABLED); physic.enable_gravity (true); } else { @@ -87,9 +104,17 @@ UnstableTile::update(float elapsed_time) case STATE_NORMAL: break; - case STATE_DISSOLVE: + case STATE_SHAKE: if (sprite->animation_done()) + dissolve (); + break; + + case STATE_DISSOLVE: + if (sprite->animation_done()) { + /* dissolving is done. Set to non-solid. */ + set_group (COLGROUP_DISABLED); fall_down (); + } break; case STATE_FALL: diff --git a/src/object/unstable_tile.hpp b/src/object/unstable_tile.hpp index 0abbacb10..aea657ddf 100644 --- a/src/object/unstable_tile.hpp +++ b/src/object/unstable_tile.hpp @@ -37,13 +37,15 @@ public: private: enum State { STATE_NORMAL, /**< default state */ - STATE_DISSOLVE, /**< crumbling, still solid */ - STATE_FALL /**< disintegrating, no longer solid */ + STATE_SHAKE, /**< shaking, still solid */ + STATE_DISSOLVE, /**< dissolving, will turn non-solid after this */ + STATE_FALL /**< falling down */ }; void startCrumbling(); private: + void shake (void); void dissolve (void); void fall_down (void);