Avoid the 'machine gun like' sound effect caused by

repeatedly playing the crash sound - which is caused by
1) collisions reported more than once (since it takes
   a few frames till a collision is resolved)
2) collision between karts and tracks when accelerating,
   which is most likely caused by the chassis hitting
   the ground (that might be fixed by better physics
   parameters).



git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1447 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2008-02-07 10:10:27 +00:00
parent df8095809e
commit 34580af755
3 changed files with 30 additions and 13 deletions

View File

@ -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))

View File

@ -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

View File

@ -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);