supertux
thunderstorm.hpp
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 
17 #ifndef HEADER_SUPERTUX_OBJECT_THUNDERSTORM_HPP
18 #define HEADER_SUPERTUX_OBJECT_THUNDERSTORM_HPP
19 
20 #include <list>
21 #include <map>
22 
23 #include "supertux/game_object.hpp"
24 #include "supertux/timer.hpp"
25 
26 class DrawingContext;
27 class ReaderMapping;
28 
38 class Thunderstorm final : public GameObject
39 {
40 public:
41  static void register_class(ssq::VM& vm);
42 
43 public:
44  Thunderstorm(const ReaderMapping& reader);
45 
46  virtual void update(float dt_sec) override;
47  virtual void draw(DrawingContext& context) override;
48 
49  static std::string class_name() { return "thunderstorm"; }
50  virtual std::string get_class_name() const override { return class_name(); }
51  virtual std::string get_exposed_class_name() const override { return "Thunderstorm"; }
52  static std::string display_name() { return _("Thunderstorm"); }
53  virtual std::string get_display_name() const override { return display_name(); }
54  virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(Thunderstorm)); }
55 
56  virtual ObjectSettings get_settings() override;
57 
58  virtual const std::string get_icon_path() const override { return "images/engine/editor/thunderstorm.png"; }
59 
67  void start();
72  void stop();
73 
78  void thunder();
83  void lightning();
84 
89  void flash();
94  void electrify();
95 
98 private:
99  void lightning_general(bool is_scripted = false);
100 
101  void change_background_colors(bool is_lightning, bool is_scripted = false);
102  void restore_background_colors();
103 
104 private:
105  bool running;
106  float interval;
107  int layer;
109  std::string m_strike_script;
110 
111  Timer time_to_thunder;
112  Timer time_to_lightning;
113  Timer flash_display_timer;
114  Timer restore_background_color_timer; /*Helps return the background color to normal */
115  std::list<Color> m_background_colors; /*Helps return the background color to normal */
116 
117  std::map<uint32_t, uint32_t> changing_tiles;
118  Color m_flash_color;
119 
120 private:
121  Thunderstorm(const Thunderstorm&) = delete;
122  Thunderstorm& operator=(const Thunderstorm&) = delete;
123 };
124 
125 #endif
126 
127 /* EOF */
void stop()
Stops playing thunder and lightning at a configured interval.
Definition: thunderstorm.cpp:167
void electrify()
Electrifies water throughout the whole sector for a short time.
Definition: thunderstorm.cpp:196
Definition: object_settings.hpp:39
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: thunderstorm.cpp:91
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: thunderstorm.hpp:53
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: thunderstorm.cpp:134
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: thunderstorm.hpp:54
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
void start()
Starts playing thunder and lightning at a configured interval.
Definition: thunderstorm.cpp:158
void lightning()
Plays lightning, i.e.
Definition: thunderstorm.cpp:183
Thunderstorm scriptable GameObject: Plays thunder, lightning and electrifies water at regular interva...
Definition: thunderstorm.hpp:38
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
Definition: color.hpp:26
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
void flash()
Displays a flash.
Definition: thunderstorm.cpp:189
void thunder()
Plays thunder.
Definition: thunderstorm.cpp:176
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
Definition: reader_mapping.hpp:32
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42