From c0fbf21f8a50fa65a23eff9a5648f8f8d039ce8c Mon Sep 17 00:00:00 2001 From: hikerstk Date: Sun, 21 Aug 2011 21:56:49 +0000 Subject: [PATCH] Added bounce sound effect for rubber balls. For now(!) this is just reusing the race-start 'ping', so this needs to be replaced with a better sfx!! git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9598 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/items/rubber_ball.cpp | 16 ++++++++++++++++ src/items/rubber_ball.hpp | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/items/rubber_ball.cpp b/src/items/rubber_ball.cpp index 7275de014..3156ab4ea 100644 --- a/src/items/rubber_ball.cpp +++ b/src/items/rubber_ball.cpp @@ -19,6 +19,8 @@ #include "items/rubber_ball.hpp" +#include "audio/sfx_base.hpp" +#include "audio/sfx_manager.hpp" #include "items/projectile_manager.hpp" #include "karts/kart.hpp" #include "modes/linear_world.hpp" @@ -64,8 +66,17 @@ RubberBall::RubberBall(Kart *kart) m_timer = 0.0f; m_interval = m_st_interval; m_current_max_height = m_max_height; + m_ping_sfx = sfx_manager->createSoundSource("ball_bounce"); } // RubberBall +// ----------------------------------------------------------------------------- +RubberBall::~RubberBall() +{ + if(m_ping_sfx->getStatus()==SFXManager::SFX_PLAYING) + m_ping_sfx->stop(); + sfx_manager->deleteSFX(m_ping_sfx); +} // ~RubberBall + // ----------------------------------------------------------------------------- /** Sets up the control points for the interpolation. The parameter contains * the coordinates of the first control points (i.e. a control point that @@ -309,6 +320,11 @@ float RubberBall::updateHeight() if(m_timer>m_interval) { m_timer -= m_interval; + if(m_ping_sfx->getStatus()!=SFXManager::SFX_PLAYING) + { + m_ping_sfx->position(getXYZ()); + m_ping_sfx->play(); + } LinearWorld *world = dynamic_cast(World::getWorld()); float target_distance = diff --git a/src/items/rubber_ball.hpp b/src/items/rubber_ball.hpp index f1330b7ac..a198ba1f0 100644 --- a/src/items/rubber_ball.hpp +++ b/src/items/rubber_ball.hpp @@ -25,6 +25,7 @@ class Kart; class QuadGraph; +class SFXBase; /** * \ingroup items @@ -106,6 +107,12 @@ private: * used to keep track of the state of this ball. */ bool m_aiming_at_target; + /** A 'ping' sound effect to be played when the ball hits the ground. */ + SFXBase *m_ping_sfx; + + /** Sound effect to be played when a ball hits a kart. */ + SFXBase *m_hit_sfx; + void computeTarget(); void checkDistanceToTarget(); unsigned int getSuccessorToHitTarget(unsigned int node_index, @@ -116,6 +123,7 @@ private: void initializeControlPoints(const Vec3 &xyz); public: RubberBall (Kart* kart); + virtual ~RubberBall(); static void init(const XMLNode &node, scene::IMesh *bowling); virtual void update (float dt); virtual void hit (Kart* kart, PhysicalObject* obj=NULL);