1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2011-2015 Joerg Henrichs
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 #include "graphics/hit_sfx.hpp"
20
21 #include "audio/sfx_base.hpp"
22 #include "audio/sfx_manager.hpp"
23 #include "race/race_manager.hpp"
24
25 /** Creates a sound effect when something was hit. */
HitSFX(const Vec3 & coord,const char * explosion_sound)26 HitSFX::HitSFX(const Vec3& coord, const char* explosion_sound)
27 : HitEffect()
28 {
29 m_sfx = SFXManager::get()->createSoundSource( explosion_sound );
30
31 // in multiplayer mode, sounds are NOT positional (because we have
32 // multiple listeners) so the sounds of all AIs are constantly heard.
33 // Therefore reduce volume of sounds.
34 float vol = RaceManager::get()->getNumLocalPlayers() > 1 ? 0.5f : 1.0f;
35 m_sfx->setVolume(vol);
36 m_sfx->play(coord);
37 } // HitSFX
38
39 //-----------------------------------------------------------------------------
40 /** Destructor stops the explosion sfx from being played and frees its memory.
41 */
~HitSFX()42 HitSFX::~HitSFX()
43 {
44 m_sfx->deleteSFX();
45 } // ~HitEffect
46
47 //-----------------------------------------------------------------------------
48 /** Called if this hit effect is for a player kart (in which case it might be
49 * played louder than for a non-player kart if split screen is used).
50 * If this sfx is for a player kart in split screen, make it louder again.
51 */
setLocalPlayerKartHit()52 void HitSFX::setLocalPlayerKartHit()
53 {
54 if(RaceManager::get()->getNumLocalPlayers())
55 m_sfx->setVolume(1.0f);
56 } // setLocalPlayerKartHit
57
58 //-----------------------------------------------------------------------------
59 /** Updates the hit sfx, called one per time step. If this function returns
60 * true, the effect will be deleted.
61 * \param dt Time step size.
62 * \return true If the explosion is finished.
63 */
updateAndDelete(int ticks)64 bool HitSFX::updateAndDelete(int ticks)
65 {
66 SFXBase::SFXStatus status = m_sfx->getStatus();
67 return status!= SFXBase::SFX_PLAYING;
68 } // updateAndDelete
69