supertux
ambient_sound.hpp
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 
18 #ifndef HEADER_SUPERTUX_OBJECT_AMBIENT_SOUND_HPP
19 #define HEADER_SUPERTUX_OBJECT_AMBIENT_SOUND_HPP
20 
21 #include "math/vector.hpp"
22 #include "supertux/moving_object.hpp"
23 #include "video/layer.hpp"
24 
25 class GameObject;
26 class ReaderMapping;
27 class SoundSource;
28 
35 class AmbientSound final : public MovingObject
36 {
37 public:
38  static void register_class(ssq::VM& vm);
39 
40 public:
41  AmbientSound(const ReaderMapping& mapping);
42  AmbientSound(const Vector& pos, float radius, float vol, const std::string& file);
43  ~AmbientSound() override;
44 
45  virtual HitResponse collision(GameObject& other, const CollisionHit& hit_) override;
46 
47  static std::string class_name() { return "ambient-sound"; }
48  virtual std::string get_class_name() const override { return class_name(); }
49  virtual std::string get_exposed_class_name() const override { return "AmbientSound"; }
50  static std::string display_name() { return _("Ambient Sound"); }
51  virtual std::string get_display_name() const override { return display_name(); }
52  virtual bool has_variable_size() const override { return true; }
53  virtual GameObjectClasses get_class_types() const override { return MovingObject::get_class_types().add(typeid(AmbientSound)); }
54 
55  virtual void draw(DrawingContext& context) override;
56 
57  virtual ObjectSettings get_settings() override;
58 
59  virtual int get_layer() const override { return LAYER_OBJECTS; }
60 
61  virtual void stop_looping_sounds() override;
62  virtual void play_looping_sounds() override;
63 
64 #ifdef DOXYGEN_SCRIPTING
65 
70  float get_pos_x() const;
76  float get_pos_y() const;
77 #endif
78 
79 protected:
80  virtual void update(float dt_sec) override;
81 
82 private:
83  void prepare_sound_source();
84 
85 private:
86  std::string m_sample;
87  std::unique_ptr<SoundSource> m_sound_source;
88 
89  float m_radius;
90  float m_radius_in_px;
91  float m_volume;
92  bool m_has_played_sound;
93 
94 private:
95  AmbientSound(const AmbientSound&) = delete;
96  AmbientSound& operator=(const AmbientSound&) = delete;
97 };
98 
99 #endif
100 
101 /* EOF */
virtual void play_looping_sounds() override
continues all looping sounds
Definition: ambient_sound.cpp:117
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: ambient_sound.cpp:126
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: ambient_sound.cpp:102
An ""AmbientSound"" that was given a name can be controlled by scripts.
Definition: ambient_sound.hpp:35
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: ambient_sound.hpp:53
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: ambient_sound.cpp:96
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:35
A sound source represents the source of audio output.
Definition: sound_source.hpp:25
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: moving_object.hpp:49
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 bool has_variable_size() const override
Does this object have variable size (secret area trigger, wind, etc.)
Definition: ambient_sound.hpp:52
Definition: reader_mapping.hpp:32
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
virtual void stop_looping_sounds() override
stops all looping sounds
Definition: ambient_sound.cpp:110
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: ambient_sound.hpp:51
This class collects data about a collision.
Definition: collision_hit.hpp:44