thunderstorm.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // SuperTux - Thunderstorm Game Object
  2. // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.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_THUNDERSTORM_HPP
  17. #define HEADER_SUPERTUX_OBJECT_THUNDERSTORM_HPP
  18. #include <list>
  19. #include <map>
  20. #include "supertux/game_object.hpp"
  21. #include "supertux/timer.hpp"
  22. class DrawingContext;
  23. class ReaderMapping;
  24. /**
  25. * Thunderstorm scriptable GameObject: Plays thunder, lightning and
  26. electrifies water at regular interval.
  27. * @scripting
  28. * @summary A ""Thunderstorm"" that was given a name can be controlled by scripts.
  29. * @instances A ""Thunderstorm"" is instantiated by placing a definition inside a level.
  30. It can then be accessed by its name from a script or via ""sector.name"" from the console.
  31. */
  32. class Thunderstorm final : public GameObject
  33. {
  34. public:
  35. static void register_class(ssq::VM& vm);
  36. public:
  37. Thunderstorm(const ReaderMapping& reader);
  38. virtual void update(float dt_sec) override;
  39. virtual void draw(DrawingContext& context) override;
  40. static std::string class_name() { return "thunderstorm"; }
  41. virtual std::string get_class_name() const override { return class_name(); }
  42. virtual std::string get_exposed_class_name() const override { return "Thunderstorm"; }
  43. static std::string display_name() { return _("Thunderstorm"); }
  44. virtual std::string get_display_name() const override { return display_name(); }
  45. virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(Thunderstorm)); }
  46. virtual ObjectSettings get_settings() override;
  47. virtual const std::string get_icon_path() const override { return "images/engine/editor/thunderstorm.png"; }
  48. /** @name Scriptable Methods
  49. @{ */
  50. /**
  51. * @scripting
  52. * @description Starts playing thunder and lightning at a configured interval.
  53. */
  54. void start();
  55. /**
  56. * @scripting
  57. * @description Stops playing thunder and lightning at a configured interval.
  58. */
  59. void stop();
  60. /**
  61. * @scripting
  62. * @description Plays thunder.
  63. */
  64. void thunder();
  65. /**
  66. * @scripting
  67. * @description Plays lightning, i.e. calls ""flash()"" and ""electrify()"".
  68. */
  69. void lightning();
  70. /**
  71. * @scripting
  72. * @description Displays a flash.
  73. */
  74. void flash();
  75. /**
  76. * @scripting
  77. * @description Electrifies water throughout the whole sector for a short time.
  78. */
  79. void electrify();
  80. /** @} */
  81. private:
  82. void lightning_general(bool is_scripted = false);
  83. void change_background_colors(bool is_lightning, bool is_scripted = false);
  84. void restore_background_colors();
  85. private:
  86. bool running; /**< whether we currently automatically trigger lightnings */
  87. float interval; /**< time between two lightnings */
  88. int layer; /**< layer, where flash will be painted */
  89. std::string m_strike_script;
  90. Timer time_to_thunder; /**< counts down until next thunder */
  91. Timer time_to_lightning; /**< counts down until next lightning */
  92. Timer flash_display_timer; /**< counts down while flash is displayed */
  93. Timer restore_background_color_timer; /*Helps return the background color to normal */
  94. std::list<Color> m_background_colors; /*Helps return the background color to normal */
  95. std::map<uint32_t, uint32_t> changing_tiles; /**< preserves the tiles which an electrocution should change */
  96. Color m_flash_color;
  97. private:
  98. Thunderstorm(const Thunderstorm&) = delete;
  99. Thunderstorm& operator=(const Thunderstorm&) = delete;
  100. };
  101. #endif
  102. /* EOF */