explosion.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SuperTux -- Explosion object
  2. // Copyright (C) 2007 Christoph Sommer <christoph.sommer@2007.expires.deltadevelopment.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #ifndef HEADER_SUPERTUX_OBJECT_EXPLOSION_HPP
  17. #define HEADER_SUPERTUX_OBJECT_EXPLOSION_HPP
  18. #include "object/moving_sprite.hpp"
  19. #define EXPLOSION_STRENGTH_DEFAULT (1464.8f * 32.0f * 32.0f)
  20. #define EXPLOSION_STRENGTH_NEAR (1000.f * 32.0f * 32.0f)
  21. /** Just your average explosion - goes boom, hurts Tux */
  22. class Explosion final : public MovingSprite
  23. {
  24. public:
  25. /** Create new Explosion centered(!) at @c pos */
  26. Explosion(const Vector& pos, float push_strength, int num_particles=100, bool short_fuse = false);
  27. Explosion(const ReaderMapping& reader);
  28. static std::string class_name() { return "explosion"; }
  29. virtual std::string get_class_name() const override { return class_name(); }
  30. static std::string display_name() { return _("Explosion"); }
  31. virtual std::string get_display_name() const override { return display_name(); }
  32. virtual void update(float dt_sec) override;
  33. virtual void draw(DrawingContext& context) override;
  34. virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
  35. virtual bool is_saveable() const override { return false; }
  36. bool hurts() const { return hurt; }
  37. void hurts (bool val) { hurt = val; }
  38. private:
  39. /** plays sound, starts animation */
  40. void explode();
  41. private:
  42. enum State {
  43. STATE_WAITING,
  44. STATE_EXPLODING
  45. };
  46. private:
  47. bool hurt;
  48. float push_strength;
  49. int num_particles;
  50. State state;
  51. SpritePtr lightsprite;
  52. bool short_fuse;
  53. private:
  54. Explosion(const Explosion&) = delete;
  55. Explosion& operator=(const Explosion&) = delete;
  56. };
  57. #endif
  58. /* EOF */