Fix for coverity #29386
[supertux.git] / src / badguy / stalactite.cpp
index 449b592..84febae 100644 (file)
@@ -16,7 +16,9 @@
 
 #include "badguy/stalactite.hpp"
 
+#include "audio/sound_manager.hpp"
 #include "math/random_generator.hpp"
+#include "object/bullet.hpp"
 #include "object/player.hpp"
 #include "sprite/sprite.hpp"
 #include "supertux/object_factory.hpp"
@@ -33,6 +35,9 @@ Stalactite::Stalactite(const Reader& lisp) :
 {
   countMe = false;
   set_colgroup_active(COLGROUP_TOUCHABLE);
+  SoundManager::current()->preload("sounds/cracking.wav");
+  SoundManager::current()->preload("sounds/sizzle.ogg");
+  SoundManager::current()->preload("sounds/icecrash.ogg");
 }
 
 void
@@ -47,10 +52,11 @@ Stalactite::active_update(float elapsed_time)
          && player->get_bbox().p1.y < bbox.p2.y + SHAKE_RANGE_Y) {
         timer.start(SHAKE_TIME);
         state = STALACTITE_SHAKING;
+        SoundManager::current()->play("sounds/cracking.wav", get_pos());
       }
     }
   } else if(state == STALACTITE_SHAKING) {
-    shake_delta = Vector(systemRandom.rand(-3,3), 0);
+    shake_delta = Vector(graphicsRandom.rand(-3,3), 0);
     if(timer.check()) {
       state = STALACTITE_FALLING;
       physic.enable_gravity(true);
@@ -70,6 +76,7 @@ Stalactite::squish()
   physic.set_velocity_y(0);
   set_state(STATE_SQUISHED);
   sprite->set_action("squished");
+  SoundManager::current()->play("sounds/icecrash.ogg", get_pos());
   set_group(COLGROUP_MOVING_ONLY_STATIC);
   run_dead_script();
 }
@@ -114,6 +121,21 @@ Stalactite::collision_badguy(BadGuy& other, const CollisionHit& hit)
   return FORCE_MOVE;
 }
 
+HitResponse
+Stalactite::collision_bullet(Bullet& bullet, const CollisionHit& )
+{
+  if(state == STALACTITE_HANGING) {
+    timer.start(SHAKE_TIME);
+    state = STALACTITE_SHAKING;
+    bullet.remove_me();
+    if(bullet.get_type() == FIRE_BONUS)
+      SoundManager::current()->play("sounds/sizzle.ogg", get_pos());
+    SoundManager::current()->play("sounds/cracking.wav", get_pos());
+  }
+
+  return FORCE_MOVE;
+}
+
 void
 Stalactite::kill_fall()
 {