Game Development Reference
In-Depth Information
// To be implemented by the class inheriting from this.
virtual Vector & getPos() = 0;
// Get this object ￿ sID.
unsigned int getID() const { return m_id; }
// Called once per frame by the VisualizerManager.
virtual void draw()
{
// If m_sound is valid then we ￿ re playing something!
if ( m_active && m_sound != null )
{
COLOR col = GREEN;
//Is the sound within audible range?
if (!SoundSystem::withinEventRange(m_event,getPos())
{
// Change to our out of range color.
col = BLUE;
}
// Draw geometry for the active sound!
GPU::drawCross( col, getPos() );
// Render events radius if requested.
if ( VisualizerManager::doWeShowSoundRadius() )
{
// Draw geometry for the active sound!
float radius = m_event->m_max_audible_distance;
GPU::drawCircle( radius, getPos() );
}
}
else
{
// No sound instance playing.
GPU::drawCross( RED, getPos() );
}
if ( VisualizerManager::doWeShowSoundNames() )
{
// Render the text 2 metres above the geometry.
Vector text_pos = getPos();
text_pos.y += 2.0f;
GPU::renderText( m_event->m_name, text_pos() );
}
}
protected:
SoundEvent *
m_event;
SoundInstance *
m_sound_instance;
unsigned int
m_id;
static unsigned int
m_shared_id_counter;
};
Listing 11.5. Sample SoundObject base class.
This is done by having game objects that can play a sound inherited from
SoundObject. SoundObject itself inherits from VisualizerObject. Listing 11.5 con-
tains a pseudocode listing showing how a sample object is created.
Search WWH ::




Custom Search