Fix music not properly fading in again
[supertux.git] / src / object / firefly.cpp
index 9390164..0077c9b 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <math.h>
 
+#include "audio/sound_manager.hpp"
 #include "math/random_generator.hpp"
 #include "object/player.hpp"
 #include "object/sprite_particle.hpp"
@@ -27,7 +28,7 @@
 #include "util/reader.hpp"
 
 Firefly::Firefly(const Reader& lisp) :
-   MovingSprite(lisp, "images/objects/resetpoints/default-resetpoint.sprite", LAYER_TILES, COLGROUP_TOUCHABLE), 
+   MovingSprite(lisp, "images/objects/resetpoints/default-resetpoint.sprite", LAYER_TILES, COLGROUP_TOUCHABLE),
    activated(false),
    initial_position()
 {
@@ -42,9 +43,17 @@ Firefly::Firefly(const Reader& lisp) :
     return;
   }
   //Replace sprite
-  sprite = sprite_manager->create( sprite_name );
+  sprite = SpriteManager::current()->create( sprite_name );
   bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
   reactivate();
+
+  //Load sound
+    if( sprite_name.find("vbell", 0) == std::string::npos ) {
+      SoundManager::current()->preload("sounds/savebell_low.wav");
+    }
+    else {
+      SoundManager::current()->preload("sounds/savebell2.wav");
+    }
 }
 
 void
@@ -63,7 +72,8 @@ Firefly::reactivate()
 HitResponse
 Firefly::collision(GameObject& other, const CollisionHit& )
 {
-  if(activated)
+  // If the bell is already activated, don't ring it again!
+  if(activated || sprite->get_action() == "ringing")
     return ABORT_MOVE;
 
   Player* player = dynamic_cast<Player*> (&other);
@@ -79,9 +89,16 @@ Firefly::collision(GameObject& other, const CollisionHit& )
       float vy = -cos(angle)*velocity;
       Vector pspeed = Vector(vx, vy);
       Vector paccel = Vector(0, 1000);
-      Sector::current()->add_object(new SpriteParticle("images/objects/particles/reset.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
+      Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/reset.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
     }
-    // TODO play sound
+
+    if( sprite_name.find("vbell", 0) == std::string::npos ) {
+      SoundManager::current()->play("sounds/savebell2.wav");
+    }
+    else {
+      SoundManager::current()->play("sounds/savebell_low.wav");
+    }
+
     sprite->set_action("ringing");
     GameSession::current()->set_reset_point(Sector::current()->get_name(),
                                             initial_position);