spotlight.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef HEADER_SUPERTUX_OBJECT_SPOTLIGHT_HPP
  17. #define HEADER_SUPERTUX_OBJECT_SPOTLIGHT_HPP
  18. #include "scripting/spotlight.hpp"
  19. #include "sprite/sprite_ptr.hpp"
  20. #include "squirrel/exposed_object.hpp"
  21. #include "supertux/moving_object.hpp"
  22. #include "video/color.hpp"
  23. class ReaderMapping;
  24. class Spotlight final : public MovingObject,
  25. public ExposedObject<Spotlight, scripting::Spotlight>
  26. {
  27. public:
  28. enum class Direction {
  29. CLOCKWISE,
  30. COUNTERCLOCKWISE,
  31. STOPPED
  32. };
  33. static Direction Direction_from_string(const std::string& s);
  34. static std::string Direction_to_string(Direction dir);
  35. public:
  36. Spotlight(const ReaderMapping& reader);
  37. ~Spotlight() override;
  38. virtual void update(float dt_sec) override;
  39. virtual void draw(DrawingContext& context) override;
  40. virtual HitResponse collision(GameObject& other, const CollisionHit& hit_) override;
  41. static std::string class_name() { return "spotlight"; }
  42. virtual std::string get_class_name() const override { return class_name(); }
  43. static std::string display_name() { return _("Spotlight"); }
  44. virtual std::string get_display_name() const override { return display_name(); }
  45. virtual ObjectSettings get_settings() override;
  46. virtual int get_layer() const override { return m_layer; }
  47. void set_enabled(bool enabled) { m_enabled = enabled; }
  48. bool is_enabled() const { return m_enabled; }
  49. void set_angle(float angle_) { angle = angle_; }
  50. void set_speed(float speed_) { speed = speed_; }
  51. void set_color(Color color_) { color = color_; }
  52. void set_direction(Direction dir) { m_direction = dir; }
  53. void ease_angle(float time, float target, EasingMode ease = EasingMode::EaseNone)
  54. {
  55. m_fade_helpers.push_back(std::make_unique<FadeHelper>(&angle, time, target, getEasingByName(ease)));
  56. }
  57. void ease_speed(float time, float target, EasingMode ease = EasingMode::EaseNone)
  58. {
  59. m_fade_helpers.push_back(std::make_unique<FadeHelper>(&speed, time, target, getEasingByName(ease)));
  60. }
  61. void ease_color(float time, Color target, EasingMode ease = EasingMode::EaseNone)
  62. {
  63. m_fade_helpers.push_back(std::make_unique<FadeHelper>(&color.red, time, target.red, getEasingByName(ease)));
  64. m_fade_helpers.push_back(std::make_unique<FadeHelper>(&color.green, time, target.green, getEasingByName(ease)));
  65. m_fade_helpers.push_back(std::make_unique<FadeHelper>(&color.blue, time, target.blue, getEasingByName(ease)));
  66. m_fade_helpers.push_back(std::make_unique<FadeHelper>(&color.alpha, time, target.alpha, getEasingByName(ease)));
  67. }
  68. private:
  69. float angle;
  70. SpritePtr center;
  71. SpritePtr base;
  72. SpritePtr lights;
  73. SpritePtr light;
  74. SpritePtr lightcone;
  75. Color color;
  76. /** Speed that the spotlight is rotating with */
  77. float speed;
  78. /** The direction of the spotlight */
  79. Direction m_direction;
  80. /** The layer (z-pos) of the spotlight. */
  81. int m_layer;
  82. bool m_enabled;
  83. private:
  84. Spotlight(const Spotlight&) = delete;
  85. Spotlight& operator=(const Spotlight&) = delete;
  86. };
  87. #endif
  88. /* EOF */