thunderstorm.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "squirrel/exposed_object.hpp"
  21. #include "scripting/thunderstorm.hpp"
  22. #include "supertux/game_object.hpp"
  23. #include "supertux/timer.hpp"
  24. class DrawingContext;
  25. class ReaderMapping;
  26. /** Thunderstorm scriptable GameObject; plays thunder, lightning and
  27. electrifies water at regular interval */
  28. class Thunderstorm final : public GameObject,
  29. public ExposedObject<Thunderstorm, scripting::Thunderstorm>
  30. {
  31. public:
  32. Thunderstorm(const ReaderMapping& reader);
  33. virtual void update(float dt_sec) override;
  34. virtual void draw(DrawingContext& context) override;
  35. static std::string class_name() { return "thunderstorm"; }
  36. virtual std::string get_class_name() const override { return class_name(); }
  37. static std::string display_name() { return _("Thunderstorm"); }
  38. virtual std::string get_display_name() const override { return display_name(); }
  39. virtual ObjectSettings get_settings() override;
  40. virtual const std::string get_icon_path() const override { return "images/engine/editor/thunderstorm.png"; }
  41. /** @name Scriptable Methods
  42. @{ */
  43. /** Start playing thunder and lightning at configured interval */
  44. void start();
  45. /** Stop playing thunder and lightning at configured interval */
  46. void stop();
  47. /** Play thunder */
  48. void thunder();
  49. /** Methods for doing lightning by different methods. Necessary for the future implementation of SimpleSquirrel. */
  50. void lightning_general();
  51. void lightning();
  52. void lightning_in_sequence();
  53. /** Display a nice flash */
  54. void flash();
  55. /** Electrify water throughout the whole sector for a short time */
  56. void electrify();
  57. /** @} */
  58. private:
  59. void change_background_colors(bool is_lightning, bool is_scripted = false);
  60. void restore_background_colors();
  61. private:
  62. bool running; /**< whether we currently automatically trigger lightnings */
  63. float interval; /**< time between two lightnings */
  64. int layer; /**< layer, where flash will be painted */
  65. std::string m_strike_script;
  66. Timer time_to_thunder; /**< counts down until next thunder */
  67. Timer time_to_lightning; /**< counts down until next lightning */
  68. Timer flash_display_timer; /**< counts down while flash is displayed */
  69. Timer restore_background_color_timer; /*Helps return the background color to normal */
  70. std::list<Color> m_background_colors; /*Helps return the background color to normal */
  71. std::map<uint32_t, uint32_t> changing_tiles; /**< preserves the tiles which an electrocution should change */
  72. Color m_flash_color;
  73. private:
  74. Thunderstorm(const Thunderstorm&) = delete;
  75. Thunderstorm& operator=(const Thunderstorm&) = delete;
  76. };
  77. #endif
  78. /* EOF */