| 1 | // SuperTux - Unstable Tile |
| 2 | // Copyright (C) 2006 Matthias Braun <matze@braunis.de> |
| 3 | // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de> |
| 4 | // Copyright (C) 2010 Florian Forster <supertux at octo.it> |
| 5 | // |
| 6 | // This program is free software: you can redistribute it and/or modify |
| 7 | // it under the terms of the GNU General Public License as published by |
| 8 | // the Free Software Foundation, either version 3 of the License, or |
| 9 | // (at your option) any later version. |
| 10 | // |
| 11 | // This program is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | // |
| 16 | // You should have received a copy of the GNU General Public License |
| 17 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | |
| 19 | #ifndef HEADER_SUPERTUX_OBJECT_UNSTABLE_TILE_HPP |
| 20 | #define |
| 21 | |
| 22 | #include "object/moving_sprite.hpp" |
| 23 | #include "supertux/physic.hpp" |
| 24 | |
| 25 | /** A block that disintegrates when stood on */ |
| 26 | class UnstableTile final : public MovingSprite |
| 27 | { |
| 28 | public: |
| 29 | UnstableTile(const ReaderMapping& mapping); |
| 30 | |
| 31 | virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override; |
| 32 | virtual void update(float dt_sec) override; |
| 33 | virtual std::string get_class() const override { return "unstable_tile" ; } |
| 34 | virtual std::string get_display_name() const override { return _("Unstable Tile" ); } |
| 35 | |
| 36 | private: |
| 37 | enum State { |
| 38 | STATE_NORMAL, /**< default state */ |
| 39 | STATE_SHAKE, /**< shaking, still solid */ |
| 40 | STATE_DISSOLVE, /**< dissolving, will turn non-solid after this */ |
| 41 | STATE_SLOWFALL, /**< slow fall phase (used when neither shaking nor dissolving exist */ |
| 42 | STATE_FALL /**< falling down */ |
| 43 | }; |
| 44 | |
| 45 | private: |
| 46 | void startCrumbling(); |
| 47 | void shake(); |
| 48 | void dissolve(); |
| 49 | void fall_down(); |
| 50 | void slow_fall(); |
| 51 | |
| 52 | private: |
| 53 | Physic physic; |
| 54 | State state; |
| 55 | float slowfall_timer; |
| 56 | |
| 57 | private: |
| 58 | UnstableTile(const UnstableTile&) = delete; |
| 59 | UnstableTile& operator=(const UnstableTile&) = delete; |
| 60 | }; |
| 61 | |
| 62 | #endif |
| 63 | |
| 64 | /* EOF */ |
| 65 | |