ambient_sound.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SuperTux
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  3. // 2023 mrkubax10 <mrkubax10@onet.pl>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef HEADER_SUPERTUX_OBJECT_AMBIENT_SOUND_HPP
  18. #define HEADER_SUPERTUX_OBJECT_AMBIENT_SOUND_HPP
  19. #include "math/vector.hpp"
  20. #include "supertux/moving_object.hpp"
  21. #include "scripting/ambient_sound.hpp"
  22. #include "squirrel/exposed_object.hpp"
  23. #include "video/layer.hpp"
  24. class GameObject;
  25. class ReaderMapping;
  26. class SoundSource;
  27. class AmbientSound final : public MovingObject,
  28. public ExposedObject<AmbientSound, scripting::AmbientSound>
  29. {
  30. public:
  31. AmbientSound(const ReaderMapping& mapping);
  32. AmbientSound(const Vector& pos, float radius, float vol, const std::string& file);
  33. ~AmbientSound() override;
  34. virtual HitResponse collision(GameObject& other, const CollisionHit& hit_) override;
  35. static std::string class_name() { return "ambient-sound"; }
  36. virtual std::string get_class_name() const override { return class_name(); }
  37. static std::string display_name() { return _("Ambient Sound"); }
  38. virtual std::string get_display_name() const override { return display_name(); }
  39. virtual bool has_variable_size() const override { return true; }
  40. /** @name Scriptable Methods
  41. @{ */
  42. #ifndef SCRIPTING_API
  43. virtual void set_pos(const Vector& pos) override;
  44. #endif
  45. void set_pos(float x, float y);
  46. float get_pos_x() const;
  47. float get_pos_y() const;
  48. /** @} */
  49. virtual void draw(DrawingContext& context) override;
  50. virtual ObjectSettings get_settings() override;
  51. virtual int get_layer() const override { return LAYER_OBJECTS; }
  52. virtual void stop_looping_sounds() override;
  53. virtual void play_looping_sounds() override;
  54. protected:
  55. virtual void update(float dt_sec) override;
  56. private:
  57. void prepare_sound_source();
  58. private:
  59. std::string m_sample;
  60. std::unique_ptr<SoundSource> m_sound_source;
  61. float m_radius;
  62. float m_radius_in_px;
  63. float m_volume;
  64. bool m_has_played_sound;
  65. private:
  66. AmbientSound(const AmbientSound&) = delete;
  67. AmbientSound& operator=(const AmbientSound&) = delete;
  68. };
  69. #endif
  70. /* EOF */