weak_block.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SuperTux - Weak Block
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  3. // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef HEADER_SUPERTUX_OBJECT_WEAK_BLOCK_HPP
  18. #define HEADER_SUPERTUX_OBJECT_WEAK_BLOCK_HPP
  19. #include "object/moving_sprite.hpp"
  20. class Bullet;
  21. /** A block that can be destroyed by Bullet hits */
  22. class WeakBlock final : public MovingSprite
  23. {
  24. public:
  25. WeakBlock(const ReaderMapping& mapping);
  26. virtual HitResponse collision(MovingObject& other, const CollisionHit& hit) override;
  27. virtual void update(float dt_sec) override;
  28. virtual void draw(DrawingContext& context) override;
  29. static std::string class_name() { return "weak_block"; }
  30. virtual std::string get_class_name() const override { return class_name(); }
  31. static std::string display_name() { return _("Weak Tile"); }
  32. virtual std::string get_display_name() const override { return display_name(); }
  33. virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(WeakBlock)); }
  34. std::vector<std::string> get_patches() const override;
  35. void update_version() override;
  36. void save(Writer& writer) override;
  37. GameObjectTypes get_types() const override;
  38. std::string get_default_sprite_name() const override;
  39. virtual void on_flip(float height) override;
  40. void startBurning();
  41. private:
  42. virtual HitResponse collision_bullet(Bullet& bullet, const CollisionHit& hit);
  43. private:
  44. /** called by self when hit by a bullet */
  45. /** pass hit to nearby WeakBlock objects */
  46. void spreadHit();
  47. private:
  48. enum Type {
  49. ICE,
  50. HAY
  51. };
  52. enum State {
  53. STATE_NORMAL, /**< default state */
  54. STATE_BURNING, /**< on fire, still solid */
  55. STATE_DISINTEGRATING /**< crumbling to dust, no longer solid */
  56. };
  57. private:
  58. State state;
  59. SpritePtr lightsprite;
  60. private:
  61. WeakBlock(const WeakBlock&) = delete;
  62. WeakBlock& operator=(const WeakBlock&) = delete;
  63. };
  64. #endif
  65. /* EOF */