diff options
| author | manuel <manuel@mausz.at> | 2011-04-08 15:18:38 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-08 15:18:38 +0200 |
| commit | 507f8b6ca5679c4898b721520dd4011f6b9e5824 (patch) | |
| tree | ba162976ed22e04586f6268db6a2e46621c1c036 /pacman-c++/actor.cpp | |
| parent | d1d48ba62695572a2091867b827b1304b0da08d3 (diff) | |
| download | foop-507f8b6ca5679c4898b721520dd4011f6b9e5824.tar.gz foop-507f8b6ca5679c4898b721520dd4011f6b9e5824.tar.bz2 foop-507f8b6ca5679c4898b721520dd4011f6b9e5824.zip | |
make audioplayer useful
Diffstat (limited to 'pacman-c++/actor.cpp')
| -rw-r--r-- | pacman-c++/actor.cpp | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 7358756..2b65528 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | #include "actor.h" | 1 | #include "actor.h" |
| 2 | #include "animationmanager.h" | 2 | #include "animationmanager.h" |
| 3 | #include "audioplayer.h" | ||
| 3 | #include <QtCore/QPropertyAnimation> | 4 | #include <QtCore/QPropertyAnimation> |
| 4 | #include <QtCore/QVariantAnimation> | 5 | #include <QtCore/QVariantAnimation> |
| 5 | #include <phonon/AudioOutput> | ||
| 6 | #include <QDebug> | 6 | #include <QDebug> |
| 7 | 7 | ||
| 8 | static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal progress) | 8 | static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal progress) |
| @@ -47,15 +47,7 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | |||
| 47 | m_eating.append(setupEatingAnimation(Actor::Down)); | 47 | m_eating.append(setupEatingAnimation(Actor::Down)); |
| 48 | 48 | ||
| 49 | /* setup player */ | 49 | /* setup player */ |
| 50 | m_player = new Phonon::MediaObject(this); | 50 | connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(enqueue())); |
| 51 | Phonon::AudioOutput *audio_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); | ||
| 52 | Phonon::createPath(m_player, audio_output); | ||
| 53 | connect(m_player, SIGNAL(finished()), this, SLOT(enqueue())); | ||
| 54 | |||
| 55 | /* preload sounds */ | ||
| 56 | m_sounds.append(new QFile(":/sound/wakawaka")); | ||
| 57 | m_sounds.append(new QFile(":/sound/die")); | ||
| 58 | m_sounds.append(new QFile(":/sound/eatingcherry")); | ||
| 59 | 51 | ||
| 60 | /* make the picture showing the current direction visible */ | 52 | /* make the picture showing the current direction visible */ |
| 61 | m_images[m_direction]->setVisible(true); | 53 | m_images[m_direction]->setVisible(true); |
| @@ -114,11 +106,9 @@ void Actor::move(Actor::Movement direction) | |||
| 114 | if (isMoving()) | 106 | if (isMoving()) |
| 115 | return; | 107 | return; |
| 116 | 108 | ||
| 117 | if (m_local && m_player->state() != Phonon::PlayingState) | 109 | if (m_local && AudioPlayer::self()->state() != Phonon::PlayingState) |
| 118 | { | 110 | { |
| 119 | m_player->stop(); | 111 | AudioPlayer::self()->play(AudioPlayer::WakaWaka); |
| 120 | m_player->setCurrentSource(m_sounds[0]); | ||
| 121 | m_player->play(); | ||
| 122 | } | 112 | } |
| 123 | 113 | ||
| 124 | /* stop current animation */ | 114 | /* stop current animation */ |
| @@ -184,23 +174,19 @@ bool Actor::isMoving() | |||
| 184 | void Actor::enqueue() | 174 | void Actor::enqueue() |
| 185 | { | 175 | { |
| 186 | if (isMoving()) | 176 | if (isMoving()) |
| 187 | m_player->enqueue(m_sounds[0]); | 177 | AudioPlayer::self()->enqueue(AudioPlayer::WakaWaka); |
| 188 | } | 178 | } |
| 189 | 179 | ||
| 190 | void Actor::die() | 180 | void Actor::die() |
| 191 | { | 181 | { |
| 192 | if (!m_local) | 182 | if (!m_local) |
| 193 | return; | 183 | return; |
| 194 | m_player->stop(); | 184 | AudioPlayer::self()->play(AudioPlayer::Die); |
| 195 | m_player->setCurrentSource(m_sounds[1]); | ||
| 196 | m_player->play(); | ||
| 197 | } | 185 | } |
| 198 | 186 | ||
| 199 | void Actor::eatingCherry() | 187 | void Actor::eatingCherry() |
| 200 | { | 188 | { |
| 201 | if (!m_local) | 189 | if (!m_local) |
| 202 | return; | 190 | return; |
| 203 | m_player->stop(); | 191 | AudioPlayer::self()->play(AudioPlayer::EatingCherry); |
| 204 | m_player->setCurrentSource(m_sounds[2]); | ||
| 205 | m_player->play(); | ||
| 206 | } | 192 | } |
