supertux
rublight.hpp
1 // SuperTux
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef HEADER_SUPERTUX_OBJECT_RUBLIGHT_HPP
17 #define HEADER_SUPERTUX_OBJECT_RUBLIGHT_HPP
18 
19 #include "object/moving_sprite.hpp"
20 #include "sprite/sprite_ptr.hpp"
21 #include "video/color.hpp"
22 
24 class RubLight final : public MovingSprite
25 {
26 public:
27  RubLight(const ReaderMapping& mapping);
28 
29  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
30  virtual void update(float dt_sec) override;
31  virtual void draw(DrawingContext& context) override;
32  static std::string class_name() { return "rublight"; }
33  virtual std::string get_class_name() const override { return class_name(); }
34  static std::string display_name() { return _("Rublight"); }
35  virtual std::string get_display_name() const override { return display_name(); }
36  virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(RubLight)); }
37  virtual ObjectSettings get_settings() override;
38 
39  virtual void on_flip(float height) override;
40 
41 private:
42  enum State {
43  STATE_DARK,
44  STATE_FADING
45  };
46 
47  State state;
48  float stored_energy;
49  SpritePtr light;
50 
51  Color color;
52  float fading_speed;
53  float strength_multiplier;
54 
55 private:
56  void rub(float strength);
57  float get_brightness() const;
58 
59  RubLight(const RubLight&) = delete;
60  RubLight& operator=(const RubLight&) = delete;
61 };
62 
63 #endif
64 
65 /* EOF */
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: rublight.hpp:35
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: rublight.hpp:36
Definition: object_settings.hpp:39
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: rublight.cpp:66
A triboluminescent (or something similar) block.
Definition: rublight.hpp:24
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: rublight.cpp:150
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: moving_sprite.hpp:60
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
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: rublight.cpp:106
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
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: rublight.cpp:136
Definition: reader_mapping.hpp:32
Abstract base class for ""MovingObject""s, that are represented by a sprite.
Definition: moving_sprite.hpp:33
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
This class collects data about a collision.
Definition: collision_hit.hpp:44