made the phone ringing again
authorMarek Moeckel <wansti@gmx.de>
Mon, 23 May 2005 14:32:32 +0000 (14:32 +0000)
committerMarek Moeckel <wansti@gmx.de>
Mon, 23 May 2005 14:32:32 +0000 (14:32 +0000)
SVN-Revision: 2539

src/object/ambient_sound.cpp
src/object/ambient_sound.h
src/object/infoblock.cpp
src/object/infoblock.h

index 7456c80..ad5b896 100644 (file)
@@ -76,6 +76,31 @@ AmbientSound::AmbientSound(const lisp::Lisp& lisp)
   latency=0;
 }
 
+AmbientSound::AmbientSound(Vector pos, float factor, float bias, float vol, std::string file)
+{
+
+  position.x=pos.x;
+  position.y=pos.y;
+
+  dimension.x=0;
+  dimension.y=0;
+
+  distance_factor=factor*factor;
+  distance_bias=bias*bias;
+  maximumvolume=vol;
+  sample=file;
+  
+  // set default silence_distance
+
+  if (distance_factor == 0)
+    silence_distance = 10e99;
+  else
+    silence_distance = 1/distance_factor;
+
+  playing=-1; // not playing at the beginning
+  latency=0;
+}
+
 AmbientSound::~AmbientSound() {
   stop_playing();
 }
index 864bf4a..ce39f7a 100644 (file)
@@ -52,6 +52,7 @@ class AmbientSound : public GameObject
 {
 public:
   AmbientSound(const lisp::Lisp& lisp);
+  AmbientSound(Vector pos, float factor, float bias, float vol, std::string file);
   ~AmbientSound();
 protected:
   virtual void hit(Player& player);
index 02b2ca2..2eb7ca2 100644 (file)
@@ -26,9 +26,7 @@
 #include "sprite/sprite_manager.h"
 #include "object_factory.h"
 #include "lisp/lisp.h"
-#include "audio/sound_manager.h"
 #include "sector.h"
-#include "player.h"
 
 InfoBlock::InfoBlock(const lisp::Lisp& lisp)
   : Block(sprite_manager->create("infoblock"))
@@ -41,7 +39,8 @@ InfoBlock::InfoBlock(const lisp::Lisp& lisp)
   if(!lisp.get("message", message)) {
     std::cerr << "No message in InfoBlock!\n";
   }
-  ringing = false;
+  ringing = new AmbientSound(get_pos(), 0.5, 300, 1, "phone");
+  Sector::current()->add_object(ringing);
 }
 
 InfoBlock::~InfoBlock()
@@ -49,18 +48,11 @@ InfoBlock::~InfoBlock()
 }
 
 void
-InfoBlock::update(float elapsed_time)
-{
-  elapsed_time = 0;
-  if (ringing) sound_manager->play_sound("phone",get_pos(),Sector::current()->player->get_pos());
-}
-
-void
 InfoBlock::hit(Player& )
 {
   GameSession::current()->display_info_box(message);
-  ringing = false;
   start_bounce();
+  ringing->remove_me();
 }
 
 IMPLEMENT_FACTORY(InfoBlock, "infoblock")
index 11f9927..9f6a670 100644 (file)
@@ -22,6 +22,7 @@
 #define __INFOBLOCK_H__
 
 #include "block.h"
+#include "object/ambient_sound.h"
 
 class InfoBlock : public Block
 {
@@ -31,9 +32,8 @@ public:
   
 protected:
   virtual void hit(Player& player);
-  virtual void update(float elapsed_time);
   std::string message;
-  bool ringing;
+  AmbientSound* ringing;
 };
 
 #endif