particle_zone.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // SuperTux - Particle zone : Spawn
  2. // Copyright (C) 2020 A. Semphris <semphris@protonmail.com>
  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_PARTICLE_ZONE_HPP
  17. #define HEADER_SUPERTUX_OBJECT_PARTICLE_ZONE_HPP
  18. #include "squirrel/exposed_object.hpp"
  19. // TODO: #include "scripting/wind.hpp"
  20. #include "supertux/moving_object.hpp"
  21. #include "video/layer.hpp"
  22. class ReaderMapping;
  23. /** Defines an area where a certain particle type can spawn */
  24. class ParticleZone final :
  25. public MovingObject//, // TODO: Make this area actually moveable with Squirrel
  26. //public ExposedObject<ParticleZone, scripting::Wind> // TODO: Scripting interface
  27. {
  28. public:
  29. ParticleZone(const ReaderMapping& reader);
  30. virtual void update(float dt_sec) override;
  31. virtual void draw(DrawingContext& context) override;
  32. virtual bool has_variable_size() const override { return true; }
  33. static std::string class_name() { return "particle-zone"; }
  34. virtual std::string get_class_name() const override { return class_name(); }
  35. static std::string display_name() { return _("Particle zone"); }
  36. virtual std::string get_display_name() const override { return display_name(); }
  37. virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
  38. virtual ObjectSettings get_settings() override;
  39. virtual GameObjectTypes get_types() const override;
  40. virtual int get_layer() const override { return LAYER_OBJECTS; }
  41. Rectf get_rect() {return m_col.m_bbox;}
  42. enum ParticleZoneType {
  43. /** Particles will spawn in this area */
  44. Spawn,
  45. /** Particles will die if they leave this area */
  46. Life,
  47. /** Particles will disappear instantly if they leave this area */
  48. LifeClear,
  49. /** Particles will start dying if they touch this area */
  50. Killer,
  51. /** Particles will disappear instantly if they touch this area */
  52. Destroyer
  53. };
  54. /** @name Scriptable Methods
  55. @{ */
  56. /** Sets whether or not particles can spawn in this area */
  57. void set_enabled(bool enabled) {m_enabled = enabled;}
  58. /** Returns whether or not particles can spawn in this area */
  59. bool get_enabled() const {return m_enabled;}
  60. /** Sets the name of the particle object for this area */
  61. void set_particle_name(std::string& particle_name) {m_particle_name = particle_name;}
  62. /** Returns the name of the particle object for this area */
  63. std::string get_particle_name() const {return m_particle_name;}
  64. /** Move the area around. Multiple calls stack (e. g. calling one before
  65. * the other finished will play both movements simultaneously)
  66. */
  67. //void displace(int x, int y, float time, std::string easing);
  68. /** Resize the area. Multiple calls stack (e. g. calling one before
  69. * the other finished will play both resizes simultaneously)
  70. */
  71. //void resize(int width, int height, float time, std::string easing);
  72. /** Returns the current X position of the zone */
  73. float current_x() const { return m_col.m_bbox.get_left(); }
  74. /** Returns the current Y position of the zone */
  75. float current_y() const { return m_col.m_bbox.get_top(); }
  76. /** Returns the target X position of the zone */
  77. //float target_x() {return m_col.m_bbox.get_left();}
  78. /** Returns the target Y position of the zone */
  79. //float target_y() {return m_col.m_bbox.get_left();}
  80. /** @} */
  81. class ZoneDetails {
  82. public:
  83. std::string m_particle_name;
  84. ParticleZoneType m_type;
  85. Rectf m_rect;
  86. ZoneDetails(std::string name, ParticleZoneType type, const Rectf& rect) :
  87. m_particle_name(std::move(name)),
  88. m_type(type),
  89. m_rect(rect)
  90. {
  91. }
  92. Rectf get_rect() const {return m_rect;}
  93. ParticleZoneType get_type() const {return m_type;}
  94. std::string get_particle_name() const {return m_particle_name;}
  95. };
  96. ZoneDetails get_details() {
  97. return ZoneDetails(m_particle_name, static_cast<ParticleZoneType>(m_type), m_col.m_bbox);
  98. }
  99. private:
  100. bool m_enabled;
  101. std::string m_particle_name;
  102. private:
  103. ParticleZone(const ParticleZone&) = delete;
  104. ParticleZone& operator=(const ParticleZone&) = delete;
  105. };
  106. #endif
  107. /* EOF */