diff --git a/src/physics.cpp b/src/physics.cpp index a4161bef7..8bd2a534e 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -136,8 +136,8 @@ void Physics::update(float dt) */ void Physics::KartKartCollision(Kart *kartA, Kart *kartB) { - kartA->crashed(); - kartB->crashed(); + kartA->crashed(); // will play crash sound for player karts + kartB->crashed(); Attachment *attachmentA=kartA->getAttachment(); Attachment *attachmentB=kartB->getAttachment(); @@ -162,9 +162,6 @@ void Physics::KartKartCollision(Kart *kartA, Kart *kartB) { attachmentB->moveBombFromTo(kartB, kartA); } - if(kartA->isPlayerKart()) sound_manager->playSfx(SOUND_CRASH); - if(kartB->isPlayerKart()) sound_manager->playSfx(SOUND_CRASH); - } // KartKartCollision //----------------------------------------------------------------------------- @@ -215,14 +212,22 @@ btScalar Physics::solveGroup(btCollisionObject** bodies, int numBodies, if(upB->is(UserPointer::UP_FLYABLE)) // 1.1 projectile hits track m_all_collisions.push_back(upB, upA); else if(upB->is(UserPointer::UP_KART)) - upB->getPointerKart()->crashed(); + // FIXME: sound disabled for now, since the chassis of the karts hits + // the track when accelerating, causing a constant crash sfx + // to be played. Might be fixed with better physics parameters + //upB->getPointerKart()->crashed(); + 0; // avoid VS compiler warning while the above statement is commented out } // 2) object a is a kart // ===================== else if(upA->is(UserPointer::UP_KART)) { if(upB->is(UserPointer::UP_TRACK)) - upA->getPointerKart()->crashed(); // Kart hit track + // FIXME: sound disabled for now, since the chassis of the karts hits + // the track when accelerating, causing a constant crash sfx + // to be played. Might be fixed with better physics parameters + // upA->getPointerKart()->crashed(); // Kart hit track + ; else if(upB->is(UserPointer::UP_FLYABLE)) m_all_collisions.push_back(upB, upA); // 2.1 projectile hits kart else if(upB->is(UserPointer::UP_KART)) diff --git a/src/player_kart.cpp b/src/player_kart.cpp index c20b36acc..448f80994 100644 --- a/src/player_kart.cpp +++ b/src/player_kart.cpp @@ -74,7 +74,7 @@ void PlayerKart::action(KartAction action, int value) m_controls.jump = (value!=0); break; } -} +} // action //----------------------------------------------------------------------------- void PlayerKart::steer(float dt, int steer_val) @@ -167,22 +167,31 @@ void PlayerKart::update(float dt) void PlayerKart::crashed() { Kart::crashed(); - sound_manager->playSfx( SOUND_CRASH ); -} + // A collision is usually reported several times, even when hitting + // something only once. This results in a kind of 'machine gun' + // noise by playing the crash sound over and over again. To prevent + // this, the crash sound is only played if there was at least 0.5 + // seconds since the last time it was played (for this kart) + if(world->m_clock - m_time_last_crash_sound > 0.5f) + { + sound_manager->playSfx( SOUND_CRASH ); + m_time_last_crash_sound = world->m_clock; + } +} // crashed //----------------------------------------------------------------------------- void PlayerKart::handleZipper() { Kart::handleZipper(); sound_manager->playSfx ( SOUND_WEE ); -} +} // handleZipper //----------------------------------------------------------------------------- void PlayerKart::collectedHerring(Herring* herring) { Kart::collectedHerring(herring); sound_manager->playSfx ( ( herring->getType()==HE_GREEN ) ? SOUND_UGH:SOUND_GRAB); -} +} // collectedHerring //----------------------------------------------------------------------------- void PlayerKart::reset() @@ -197,9 +206,11 @@ void PlayerKart::reset() m_controls.wheelie = false; m_controls.jump = false; m_penalty_time = 0; + m_time_last_crash_sound = -10.0f; m_camera->setReverseHeading(false); Kart::reset(); -} +} // reset + //----------------------------------------------------------------------------- /** This function is called by world to add any messages to the race gui. This * can't be done (in some cases) in the update() function, since update can be diff --git a/src/player_kart.hpp b/src/player_kart.hpp index 59c3f1202..a4d709146 100644 --- a/src/player_kart.hpp +++ b/src/player_kart.hpp @@ -37,6 +37,7 @@ private: Player *m_player; float m_penalty_time; + float m_time_last_crash_sound; Camera *m_camera; void steer(float, int);