From: Mathnerd314 Date: Sun, 17 Jan 2010 21:11:16 +0000 (+0000) Subject: UnstableTile and WeakBlock are affected by Explosions. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2d0dedeeb0639489e2b34bbaa3c41c394c85a0d2;p=supertux.git UnstableTile and WeakBlock are affected by Explosions. SVN-Revision: 6256 --- diff --git a/src/object/explosion.cpp b/src/object/explosion.cpp index 94a40d12f..77d6b17e8 100644 --- a/src/object/explosion.cpp +++ b/src/object/explosion.cpp @@ -27,14 +27,14 @@ #include Explosion::Explosion(const Vector& pos) - : MovingSprite(pos, "images/objects/explosion/explosion.sprite", LAYER_OBJECTS+40, COLGROUP_TOUCHABLE), state(STATE_WAITING) + : MovingSprite(pos, "images/objects/explosion/explosion.sprite", LAYER_OBJECTS+40, COLGROUP_MOVING), state(STATE_WAITING) { sound_manager->preload("sounds/explosion.wav"); set_pos(get_pos() - (get_bbox().get_middle() - get_pos())); } Explosion::Explosion(const Reader& reader) - : MovingSprite(reader, "images/objects/explosion/explosion.sprite", LAYER_OBJECTS+40, COLGROUP_TOUCHABLE), state(STATE_WAITING) + : MovingSprite(reader, "images/objects/explosion/explosion.sprite", LAYER_OBJECTS+40, COLGROUP_MOVING), state(STATE_WAITING) { sound_manager->preload("sounds/explosion.wav"); } diff --git a/src/object/unstable_tile.cpp b/src/object/unstable_tile.cpp index 79d6b2a18..5002d897d 100644 --- a/src/object/unstable_tile.cpp +++ b/src/object/unstable_tile.cpp @@ -17,6 +17,7 @@ #include "object/unstable_tile.hpp" +#include "object/explosion.hpp" #include "object/player.hpp" #include "sprite/sprite.hpp" #include "supertux/constants.hpp" @@ -37,14 +38,25 @@ 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) { - state = STATE_CRUMBLING; - sprite->set_action("crumbling", 1); + startCrumbling(); + } + + if (dynamic_cast (&other)) { + startCrumbling(); } } return FORCE_MOVE; } void +UnstableTile::startCrumbling() +{ + if (state != STATE_NORMAL) return; + state = STATE_CRUMBLING; + sprite->set_action("crumbling", 1); +} + +void UnstableTile::update(float elapsed_time) { switch (state) { diff --git a/src/object/unstable_tile.hpp b/src/object/unstable_tile.hpp index 4c2cf17f8..f005bf190 100644 --- a/src/object/unstable_tile.hpp +++ b/src/object/unstable_tile.hpp @@ -40,6 +40,8 @@ private: STATE_DISINTEGRATING /**< disintegrating, no longer solid */ }; + void startCrumbling(); + private: Physic physic; State state; diff --git a/src/object/weak_block.cpp b/src/object/weak_block.cpp index eae7d0c4d..b9d10c525 100644 --- a/src/object/weak_block.cpp +++ b/src/object/weak_block.cpp @@ -18,6 +18,7 @@ #include "object/weak_block.hpp" #include "object/bullet.hpp" +#include "object/explosion.hpp" #include "supertux/object_factory.hpp" #include "supertux/sector.hpp" @@ -37,22 +38,21 @@ WeakBlock::collision(GameObject& other, const CollisionHit& ) case STATE_NORMAL: if (dynamic_cast(&other)) { startBurning(); - return FORCE_MOVE; } - return FORCE_MOVE; + if (dynamic_cast (&other)) { + startBurning(); + } break; case STATE_BURNING: - return FORCE_MOVE; - break; - case STATE_DISINTEGRATING: - return FORCE_MOVE; break; + default: + log_debug << "unhandled state" << std::endl; + break; } - log_debug << "unhandled state" << std::endl; return FORCE_MOVE; }