supertux
ambient_sound.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 
39 #ifndef HEADER_SUPERTUX_OBJECT_AMBIENT_SOUND_HPP
40 #define HEADER_SUPERTUX_OBJECT_AMBIENT_SOUND_HPP
41 
42 #include "math/vector.hpp"
43 #include "supertux/moving_object.hpp"
44 #include "scripting/ambient_sound.hpp"
45 #include "squirrel/exposed_object.hpp"
46 
47 class GameObject;
48 class ReaderMapping;
49 class SoundSource;
50 
51 class AmbientSound final : public MovingObject,
52  public ExposedObject<AmbientSound, scripting::AmbientSound>
53 {
54 public:
55  AmbientSound(const ReaderMapping& mapping);
56  AmbientSound(const Vector& pos, float factor, float bias, float vol, const std::string& file);
57  ~AmbientSound();
58 
59  virtual HitResponse collision(GameObject& other, const CollisionHit& hit_) override;
60 
61  virtual std::string get_class() const override { return "ambient-sound"; }
62  virtual std::string get_display_name() const override { return _("Ambient sound"); }
63  virtual bool has_variable_size() const override { return true; }
64 
67 #ifndef SCRIPTING_API
68  virtual void set_pos(const Vector& pos) override;
69 #endif
70  void set_pos(float x, float y);
71  float get_pos_x() const;
72  float get_pos_y() const;
75  virtual void draw(DrawingContext& context) override;
76 
77  virtual ObjectSettings get_settings() override;
78  virtual void after_editor_set() override;
79 
80 protected:
81  virtual void update(float dt_sec) override;
82  virtual void start_playing();
83  virtual void stop_playing();
84 
85 private:
86  std::string sample;
87  std::unique_ptr<SoundSource> sound_source;
88  int latency;
89 
90  float distance_factor;
91  float distance_bias;
92  float silence_distance;
93 
94  float maximumvolume;
95  float targetvolume;
96  float currentvolume;
97 
98 private:
99  AmbientSound(const AmbientSound&) = delete;
100  AmbientSound& operator=(const AmbientSound&) = delete;
101 };
102 
103 #endif
104 
105 /* EOF */
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:162
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: ambient_sound.cpp:252
Simple two dimensional vector.
Definition: vector.hpp:24
This class binds a certain GameObject class to a scripting class.
Definition: exposed_object.hpp:45
Definition: ambient_sound.hpp:51
Definition: object_settings.hpp:35
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:246
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:31
A sound source represents the source of audio output.
Definition: sound_source.hpp:25
virtual bool has_variable_size() const override
Does this object have variable size (secret area trigger, wind, etc.)
Definition: ambient_sound.hpp:63
Definition: reader_mapping.hpp:31
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