From: Florian Forster Date: Sun, 28 Feb 2010 21:08:34 +0000 (+0000) Subject: Unstable tile: Dissolve, then disappear without falling down. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f6e9071d5b533f61e18f95e3dfb8087f50b3026e;p=supertux.git Unstable tile: Dissolve, then disappear without falling down. The new behavior is as follows: If the sprite has a "dissolve" action, it is triggered on contact. If the "dissolve" animation ends, or if the sprite doesn't have a "dissolve" action, the "fall-down" action is triggered. If that animation is done, or if the sprite doesn't have a "fall-down" action, the object is removed. Possible future improvements: - Make the tile non-solid at the end of "dissolve", rather than at the beginning of "fall-down". This way falling only sprites would still be solid. For this to be of use the collision detection needs to be improved, though. - Also, remove the object after is has hit a solid object or has fallen out of the screen. The "remove at end of animation" behavior is more of a dirty hack. SVN-Revision: 6479 --- diff --git a/data/images/objects/unstable_tile/castleblock.sprite b/data/images/objects/unstable_tile/castleblock.sprite index 6e44b4d91..90670dce4 100644 --- a/data/images/objects/unstable_tile/castleblock.sprite +++ b/data/images/objects/unstable_tile/castleblock.sprite @@ -6,7 +6,7 @@ ) ) (action - (name "crumbling") + (name "dissolve") (fps 8) (images "castleblock-0.png" @@ -15,11 +15,11 @@ "castleblock-3.png" ) ) - (action - (name "disintegrating") - (fps 1) - (images - "castleblock-3.png" - ) - ) +; (action +; (name "fall-down") +; (fps 1) +; (images +; "castleblock-3.png" +; ) +; ) ) diff --git a/data/images/objects/unstable_tile/snow.sprite b/data/images/objects/unstable_tile/snow.sprite index 63e715a71..2ea34ef42 100644 --- a/data/images/objects/unstable_tile/snow.sprite +++ b/data/images/objects/unstable_tile/snow.sprite @@ -6,7 +6,7 @@ ) ) (action - (name "crumbling") + (name "dissolve") (fps 8) (images "snow-0.png" @@ -21,11 +21,11 @@ "snow-9.png" ) ) - (action - (name "disintegrating") - (fps 1) - (images - "snow-9.png" - ) - ) +; (action +; (name "fall-down") +; (fps 1) +; (images +; "snow-9.png" +; ) +; ) ) diff --git a/data/images/objects/unstable_tile/unstable_tile.sprite b/data/images/objects/unstable_tile/unstable_tile.sprite index b7411027d..8b6a2bddc 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 "crumbling") + (name "dissolve") (fps 20) (images "crumbling-0.png" @@ -21,11 +21,11 @@ "crumbling-1.png" ) ) - (action - (name "disintegrating") - (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 5002d897d..0d69f151c 100644 --- a/src/object/unstable_tile.cpp +++ b/src/object/unstable_tile.cpp @@ -1,6 +1,7 @@ // SuperTux - Unstable Tile // Copyright (C) 2006 Matthias Braun // Copyright (C) 2006 Christoph Sommer +// Copyright (C) 2010 Florian Forster // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -38,47 +39,64 @@ 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) { - startCrumbling(); + dissolve (); } if (dynamic_cast (&other)) { - startCrumbling(); + dissolve (); } } return FORCE_MOVE; } -void -UnstableTile::startCrumbling() +void UnstableTile::dissolve (void) { - if (state != STATE_NORMAL) return; - state = STATE_CRUMBLING; - sprite->set_action("crumbling", 1); + if (state != STATE_NORMAL) + return; + + if (sprite->has_action ("dissolve")) { + state = STATE_DISSOLVE; + this->set_action ("dissolve", /* loops = */ 1); + } + else { + fall_down (); + } +} + +void UnstableTile::fall_down (void) +{ + if ((state != STATE_NORMAL) && (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 { + remove_me (); + } } void UnstableTile::update(float elapsed_time) { - switch (state) { - + switch (state) + { case STATE_NORMAL: break; - case STATE_CRUMBLING: - if (sprite->animation_done()) { - state = STATE_DISINTEGRATING; - sprite->set_action("disintegrating", 1); - set_group(COLGROUP_DISABLED); - physic.enable_gravity(true); - } + case STATE_DISSOLVE: + if (sprite->animation_done()) + fall_down (); break; - case STATE_DISINTEGRATING: - movement = physic.get_movement(elapsed_time); - if (sprite->animation_done()) { - remove_me(); - return; - } + case STATE_FALL: + if (sprite->animation_done()) + remove_me (); + else + movement = physic.get_movement (elapsed_time); break; } } diff --git a/src/object/unstable_tile.hpp b/src/object/unstable_tile.hpp index f005bf190..0abbacb10 100644 --- a/src/object/unstable_tile.hpp +++ b/src/object/unstable_tile.hpp @@ -1,6 +1,7 @@ // SuperTux - Unstable Tile // Copyright (C) 2006 Matthias Braun // Copyright (C) 2006 Christoph Sommer +// Copyright (C) 2010 Florian Forster // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -35,14 +36,17 @@ public: private: enum State { - STATE_NORMAL, /**< default state */ - STATE_CRUMBLING, /**< crumbling, still solid */ - STATE_DISINTEGRATING /**< disintegrating, no longer solid */ + STATE_NORMAL, /**< default state */ + STATE_DISSOLVE, /**< crumbling, still solid */ + STATE_FALL /**< disintegrating, no longer solid */ }; void startCrumbling(); private: + void dissolve (void); + void fall_down (void); + Physic physic; State state; }; diff --git a/src/sprite/sprite.hpp b/src/sprite/sprite.hpp index 24c5ed72b..2c36b0df4 100644 --- a/src/sprite/sprite.hpp +++ b/src/sprite/sprite.hpp @@ -111,6 +111,11 @@ public: return action->surfaces[frame_]; } + bool has_action (const std::string& name) + { + return (data.get_action(name) != NULL); + } + private: void update();