cloud_particle_system.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SuperTux
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.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_CLOUD_PARTICLE_SYSTEM_HPP
  17. #define HEADER_SUPERTUX_OBJECT_CLOUD_PARTICLE_SYSTEM_HPP
  18. #include "object/particlesystem.hpp"
  19. #include "scripting/clouds.hpp"
  20. #include "video/surface_ptr.hpp"
  21. class ReaderMapping;
  22. class CloudParticleSystem final :
  23. public ParticleSystem,
  24. public ExposedObject<CloudParticleSystem, scripting::Clouds>
  25. {
  26. public:
  27. CloudParticleSystem();
  28. CloudParticleSystem(const ReaderMapping& reader);
  29. ~CloudParticleSystem() override;
  30. void init();
  31. virtual void update(float dt_sec) override;
  32. virtual void draw(DrawingContext& context) override;
  33. static std::string class_name() { return "particles-clouds"; }
  34. virtual std::string get_class_name() const override { return class_name(); }
  35. static std::string display_name() { return _("Cloud Particles"); }
  36. virtual std::string get_display_name() const override { return display_name(); }
  37. virtual ObjectSettings get_settings() override;
  38. virtual const std::string get_icon_path() const override {
  39. return "images/engine/editor/clouds.png";
  40. }
  41. void fade_speed(float new_speed, float fade_time);
  42. void fade_amount(int new_amount, float fade_time, float time_between = 0.f);
  43. // Minimum and maximum multiplier for the amount of clouds
  44. static int constexpr const max_amount = 500;
  45. static int constexpr const min_amount = 0;
  46. virtual void expose(HSQUIRRELVM vm, SQInteger table_idx) override {
  47. ExposedObject<CloudParticleSystem, scripting::Clouds>::expose(vm, table_idx);
  48. }
  49. virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx) override {
  50. ExposedObject<CloudParticleSystem, scripting::Clouds>::unexpose(vm, table_idx);
  51. }
  52. private:
  53. /** Returns the amount that got inserted (In case max_amount got hit) */
  54. int add_clouds(int amount, float fade_time);
  55. /** Returns the amount that got removed (In case min_amount got hit) */
  56. int remove_clouds(int amount, float fade_time);
  57. private:
  58. class CloudParticle : public Particle
  59. {
  60. public:
  61. float speed;
  62. float target_alpha;
  63. float target_time_remaining;
  64. CloudParticle() :
  65. speed(),
  66. target_alpha(),
  67. target_time_remaining()
  68. {}
  69. };
  70. SurfacePtr cloudimage;
  71. float m_current_speed;
  72. float m_target_speed;
  73. float m_speed_fade_time_remaining;
  74. int m_current_amount;
  75. int m_current_real_amount;
  76. private:
  77. CloudParticleSystem(const CloudParticleSystem&) = delete;
  78. CloudParticleSystem& operator=(const CloudParticleSystem&) = delete;
  79. };
  80. #endif
  81. /* EOF */