diff options
| author | manuel <manuel@mausz.at> | 2011-04-25 14:39:00 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-25 14:39:00 +0200 |
| commit | 41a31420cf091aeb4e986503387855d41e550106 (patch) | |
| tree | ffbe0be5f9630a0bab2deb0b5df37c174bf40db1 /pacman-c++/audio.cpp | |
| parent | bbd2a69a962d15f74a4afcb7b66462eac9fa5008 (diff) | |
| download | foop-41a31420cf091aeb4e986503387855d41e550106.tar.gz foop-41a31420cf091aeb4e986503387855d41e550106.tar.bz2 foop-41a31420cf091aeb4e986503387855d41e550106.zip | |
- add intro sound on every round
- add dieing sound
- add dieing animation
- add die on moving onto colorized block
Diffstat (limited to 'pacman-c++/audio.cpp')
| -rw-r--r-- | pacman-c++/audio.cpp | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/pacman-c++/audio.cpp b/pacman-c++/audio.cpp index d627c75..5fb4416 100644 --- a/pacman-c++/audio.cpp +++ b/pacman-c++/audio.cpp | |||
| @@ -15,18 +15,19 @@ AudioManager::AudioManager() | |||
| 15 | : m_muted(true) | 15 | : m_muted(true) |
| 16 | { | 16 | { |
| 17 | if (Constants::server) | 17 | if (Constants::server) |
| 18 | { | ||
| 18 | qDebug() << "Server has no sound"; | 19 | qDebug() << "Server has no sound"; |
| 20 | m_players.append(new AudioPlayer(this)); | ||
| 21 | } | ||
| 19 | else | 22 | else |
| 20 | { | 23 | { |
| 21 | preload(); | 24 | preload(); |
| 22 | |||
| 23 | AudioPlayer *firstplayer = new AudioPlayer(this); | 25 | AudioPlayer *firstplayer = new AudioPlayer(this); |
| 24 | firstplayer->test(m_sounds[Sound::WakaWaka]); | 26 | firstplayer->test(m_sounds[Sound::WakaWaka]); |
| 25 | m_working = firstplayer->m_working; | 27 | m_working = firstplayer->m_working; |
| 26 | m_players.append(firstplayer); | 28 | m_players.append(firstplayer); |
| 27 | |||
| 28 | m_muted = false; | ||
| 29 | } | 29 | } |
| 30 | m_muted = false; | ||
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | AudioManager *AudioManager::self() | 33 | AudioManager *AudioManager::self() |
| @@ -97,15 +98,9 @@ AudioPlayer *AudioManager::audioPlayer() | |||
| 97 | return m_players.at(0); | 98 | return m_players.at(0); |
| 98 | } | 99 | } |
| 99 | 100 | ||
| 100 | void AudioManager::play(Sound::Type sound) | 101 | void AudioManager::play(Sound::Type sound, bool wait) |
| 101 | { | 102 | { |
| 102 | if (!isWorking()) | 103 | audioPlayer()->play(sound, wait); |
| 103 | { | ||
| 104 | emit audioPlayer()->finished(); | ||
| 105 | return; | ||
| 106 | } | ||
| 107 | |||
| 108 | audioPlayer()->play(sound); | ||
| 109 | } | 104 | } |
| 110 | 105 | ||
| 111 | void AudioManager::enqueue(Sound::Type sound) | 106 | void AudioManager::enqueue(Sound::Type sound) |
| @@ -151,11 +146,14 @@ QFile *AudioManager::sound(Sound::Type sound) | |||
| 151 | /* --------------------------------------------------------------- */ | 146 | /* --------------------------------------------------------------- */ |
| 152 | 147 | ||
| 153 | AudioPlayer::AudioPlayer(QObject *parent) | 148 | AudioPlayer::AudioPlayer(QObject *parent) |
| 154 | : Phonon::MediaObject(parent) | 149 | : Phonon::MediaObject(parent), m_working(false) |
| 155 | { | 150 | { |
| 156 | m_working = AudioManager::m_working; | 151 | if (!Constants::server) |
| 157 | m_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); | 152 | { |
| 158 | Phonon::createPath(this, m_output); | 153 | m_working = AudioManager::m_working; |
| 154 | m_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); | ||
| 155 | Phonon::createPath(this, m_output); | ||
| 156 | } | ||
| 159 | } | 157 | } |
| 160 | 158 | ||
| 161 | bool AudioPlayer::isWorking() const | 159 | bool AudioPlayer::isWorking() const |
| @@ -200,10 +198,25 @@ void AudioPlayer::play() | |||
| 200 | Phonon::MediaObject::play(); | 198 | Phonon::MediaObject::play(); |
| 201 | } | 199 | } |
| 202 | 200 | ||
| 203 | void AudioPlayer::play(Sound::Type sound) | 201 | void AudioPlayer::play(Sound::Type sound, bool wait) |
| 204 | { | 202 | { |
| 205 | setCurrentSource(Phonon::MediaSource(AudioManager::self()->sound(sound))); | 203 | if (m_working) |
| 206 | play(); | 204 | { |
| 205 | setCurrentSource(Phonon::MediaSource(AudioManager::self()->sound(sound))); | ||
| 206 | play(); | ||
| 207 | } | ||
| 208 | else if (wait) | ||
| 209 | { | ||
| 210 | QTimer *timer = new QTimer(this); | ||
| 211 | timer->setSingleShot(true); | ||
| 212 | unsigned int interval = Sound::length[sound]; | ||
| 213 | /* add a small delay server side only */ | ||
| 214 | if (Constants::server) | ||
| 215 | interval += Constants::tick; | ||
| 216 | timer->setInterval(interval); | ||
| 217 | connect(timer, SIGNAL(timeout()), this, SLOT(finished_ex())); | ||
| 218 | timer->start(); | ||
| 219 | } | ||
| 207 | } | 220 | } |
| 208 | 221 | ||
| 209 | /* this is a simple hack to check if phonon can actually play sounds.. */ | 222 | /* this is a simple hack to check if phonon can actually play sounds.. */ |
| @@ -227,6 +240,11 @@ void AudioPlayer::test(QFile *testsound) | |||
| 227 | clear(); | 240 | clear(); |
| 228 | } | 241 | } |
| 229 | 242 | ||
| 243 | void AudioPlayer::finished_ex() | ||
| 244 | { | ||
| 245 | emit finished(); | ||
| 246 | } | ||
| 247 | |||
| 230 | void AudioPlayer::stateChanged_ex(Phonon::State newstate, Phonon::State /* oldstate */) | 248 | void AudioPlayer::stateChanged_ex(Phonon::State newstate, Phonon::State /* oldstate */) |
| 231 | { | 249 | { |
| 232 | if (newstate != Phonon::ErrorState) | 250 | if (newstate != Phonon::ErrorState) |
