unstable_tile.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // 2023 Vankata453
  6. //
  7. // This program is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #ifndef HEADER_SUPERTUX_OBJECT_UNSTABLE_TILE_HPP
  20. #define HEADER_SUPERTUX_OBJECT_UNSTABLE_TILE_HPP
  21. #include "object/moving_sprite.hpp"
  22. #include "supertux/physic.hpp"
  23. #include "supertux/timer.hpp"
  24. #include "util/fade_helper.hpp"
  25. /** A block that disintegrates when stood on */
  26. class UnstableTile final : public MovingSprite
  27. {
  28. public:
  29. UnstableTile(const ReaderMapping& mapping, int type = -1);
  30. virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
  31. virtual void update(float dt_sec) override;
  32. virtual void draw(DrawingContext& context) override;
  33. virtual void on_flip(float height) override;
  34. static std::string class_name() { return "unstable_tile"; }
  35. virtual std::string get_class_name() const override { return class_name(); }
  36. static std::string display_name() { return _("Unstable Tile"); }
  37. virtual std::string get_display_name() const override { return display_name(); }
  38. GameObjectTypes get_types() const override;
  39. std::string get_default_sprite_name() const override;
  40. public:
  41. enum Type {
  42. ICE,
  43. BRICK,
  44. DELAYED
  45. };
  46. private:
  47. enum State {
  48. STATE_NORMAL, /**< default state */
  49. STATE_SHAKE, /**< shaking, still solid */
  50. STATE_DISSOLVE, /**< dissolving, will turn non-solid after this */
  51. STATE_SLOWFALL, /**< slow fall phase (used when neither shaking nor dissolving exist */
  52. STATE_FALL /**< falling down */
  53. };
  54. private:
  55. void shake();
  56. void dissolve();
  57. void fall_down();
  58. void slow_fall();
  59. void revive();
  60. private:
  61. Physic physic;
  62. State state;
  63. float slowfall_timer;
  64. Timer m_revive_timer;
  65. std::unique_ptr<FadeHelper> m_respawn;
  66. float m_alpha;
  67. Vector m_original_pos;
  68. /** DELAYED type management */
  69. Timer m_fall_timer;
  70. bool m_player_hit;
  71. private:
  72. UnstableTile(const UnstableTile&) = delete;
  73. UnstableTile& operator=(const UnstableTile&) = delete;
  74. };
  75. #endif
  76. /* EOF */