supertux
spotlight.hpp
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 
17 #ifndef HEADER_SUPERTUX_OBJECT_SPOTLIGHT_HPP
18 #define HEADER_SUPERTUX_OBJECT_SPOTLIGHT_HPP
19 
20 #include "sprite/sprite_ptr.hpp"
21 #include "supertux/moving_object.hpp"
22 #include "video/color.hpp"
23 
24 class ReaderMapping;
25 
32 class Spotlight final : public MovingObject
33 {
34 public:
35  static void register_class(ssq::VM& vm);
36 
37 public:
38  enum class Direction {
39  CLOCKWISE,
40  COUNTERCLOCKWISE,
41  STOPPED
42  };
43 
44  static Direction Direction_from_string(const std::string& s);
45  static std::string Direction_to_string(Direction dir);
46 
47 public:
48  Spotlight(const ReaderMapping& reader);
49  ~Spotlight() override;
50 
51  virtual void update(float dt_sec) override;
52  virtual void draw(DrawingContext& context) override;
53 
54  virtual HitResponse collision(GameObject& other, const CollisionHit& hit_) override;
55 
56  static std::string class_name() { return "spotlight"; }
57  virtual std::string get_class_name() const override { return class_name(); }
58  virtual std::string get_exposed_class_name() const override { return "Spotlight"; }
59  static std::string display_name() { return _("Spotlight"); }
60  virtual std::string get_display_name() const override { return display_name(); }
61  virtual GameObjectClasses get_class_types() const override { return MovingObject::get_class_types().add(typeid(Spotlight)); }
62 
63  virtual ObjectSettings get_settings() override;
64 
65  virtual int get_layer() const override { return m_layer; }
66 
73  void set_enabled(bool enabled);
79  bool is_enabled();
80 
86  void set_direction(const std::string& direction);
87 
94  void set_angle(float angle);
101  void fade_angle(float angle, float time);
109  void ease_angle(float angle, float time, const std::string& easing);
110 
117  void set_speed(float speed);
124  void fade_speed(float speed, float time);
132  void ease_speed(float speed, float time, const std::string& easing);
133 
142  void set_color_rgba(float r, float g, float b, float a);
152  void fade_color_rgba(float r, float g, float b, float a, float time);
163  void ease_color_rgba(float r, float g, float b, float a, float time, const std::string& easing);
164 
165  void ease_angle(float time, float target, EasingMode ease = EasingMode::EaseNone);
166  void ease_speed(float time, float target, EasingMode ease = EasingMode::EaseNone);
167  void ease_color(float time, Color target, EasingMode ease = EasingMode::EaseNone);
168 
169 private:
174  float m_angle;
175  SpritePtr m_center;
176  SpritePtr m_base;
177  SpritePtr m_lights;
178  SpritePtr m_light;
179  SpritePtr m_lightcone;
180 
181  Color m_color;
182 
187  float m_speed;
188 
190  Direction m_direction;
191 
193  int m_layer;
194 
199  bool m_enabled;
200 
201 private:
202  Spotlight(const Spotlight&) = delete;
203  Spotlight& operator=(const Spotlight&) = delete;
204 };
205 
206 #endif
207 
208 /* EOF */
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: spotlight.hpp:60
void set_direction(const std::string &direction)
Sets the direction of the spotlight.
Definition: spotlight.cpp:189
bool is_enabled()
Definition: spotlight.cpp:183
void ease_angle(float angle, float time, const std::string &easing)
Fades the angle of the spotlight in ""time"" seconds, with easing.
Definition: spotlight.cpp:225
void ease_color_rgba(float r, float g, float b, float a, float time, const std::string &easing)
Fades the spotlight to a new RGBA color in ""time"" seconds, with easing.
Definition: spotlight.cpp:243
virtual HitResponse collision(GameObject &other, const CollisionHit &hit_) override
this function is called when the object collided with any other object
Definition: spotlight.cpp:171
void fade_angle(float angle, float time)
Fades the angle of the spotlight in ""time"" seconds.
Definition: spotlight.cpp:219
Definition: object_settings.hpp:39
void set_color_rgba(float r, float g, float b, float a)
Sets the RGBA color of the spotlight.
Definition: spotlight.cpp:231
void fade_color_rgba(float r, float g, float b, float a, float time)
Fades the spotlight to a new RGBA color in ""time"" seconds.
Definition: spotlight.cpp:237
A ""Spotlight"" that was given a name can be controlled by scripts.
Definition: spotlight.hpp:32
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: spotlight.hpp:61
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:35
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: spotlight.cpp:119
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: moving_object.hpp:49
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: spotlight.cpp:142
Definition: color.hpp:26
void set_enabled(bool enabled)
Definition: spotlight.cpp:177
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
Definition: reader_mapping.hpp:32
void set_angle(float angle)
Definition: spotlight.cpp:213
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
void fade_speed(float speed, float time)
Fades the speed of the spotlight in ""time"" seconds.
Definition: spotlight.cpp:201
void ease_speed(float speed, float time, const std::string &easing)
Fades the speed of the spotlight in ""time"" seconds, with easing.
Definition: spotlight.cpp:207
This class collects data about a collision.
Definition: collision_hit.hpp:44
void set_speed(float speed)
Definition: spotlight.cpp:195