diff options
Diffstat (limited to 'pacman-c++/actor.cpp')
| -rw-r--r-- | pacman-c++/actor.cpp | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index bd50a3c..8184c6f 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #include "actor.h" | 1 | #include "actor.h" |
| 2 | #include "animationmanager.h" | 2 | #include "animationmanager.h" |
| 3 | #include "audioplayer.h" | ||
| 4 | #include <QtCore/QPropertyAnimation> | 3 | #include <QtCore/QPropertyAnimation> |
| 5 | #include <QtCore/QVariantAnimation> | 4 | #include <QtCore/QVariantAnimation> |
| 6 | #include <QDebug> | 5 | #include <QDebug> |
| @@ -12,7 +11,7 @@ static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal | |||
| 12 | 11 | ||
| 13 | Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | 12 | Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) |
| 14 | : PixmapItem(parent), m_color(color), m_direction(Actor::None), m_local(local), | 13 | : PixmapItem(parent), m_color(color), m_direction(Actor::None), m_local(local), |
| 15 | m_roundPoints(0), m_gamePoints(0) | 14 | m_player(NULL), m_roundPoints(0), m_gamePoints(0) |
| 16 | { | 15 | { |
| 17 | m_pix = ":/" + QString("actor%1").arg((m_color >> 1) + 1); | 16 | m_pix = ":/" + QString("actor%1").arg((m_color >> 1) + 1); |
| 18 | /* DON'T set any pixmap here. we've a pixmap in the animation | 17 | /* DON'T set any pixmap here. we've a pixmap in the animation |
| @@ -50,8 +49,16 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | |||
| 50 | m_eating.append(setupEatingAnimation(Actor::Up)); | 49 | m_eating.append(setupEatingAnimation(Actor::Up)); |
| 51 | m_eating.append(setupEatingAnimation(Actor::Down)); | 50 | m_eating.append(setupEatingAnimation(Actor::Down)); |
| 52 | 51 | ||
| 53 | /* setup player */ | 52 | /* setup sound */ |
| 54 | connect(AudioPlayer::self(), SIGNAL(aboutToFinish()), this, SLOT(enqueue())); | 53 | if (local) |
| 54 | { | ||
| 55 | m_player = new AudioPlayer(this); | ||
| 56 | if (m_player->isWorking()) | ||
| 57 | { | ||
| 58 | m_player->setLoop(Sound::WakaWaka); | ||
| 59 | AudioManager::self()->registerAudioPlayer(m_player); | ||
| 60 | } | ||
| 61 | } | ||
| 55 | 62 | ||
| 56 | /* make the picture showing the current direction visible */ | 63 | /* make the picture showing the current direction visible */ |
| 57 | m_images[m_direction]->setVisible(true); | 64 | m_images[m_direction]->setVisible(true); |
| @@ -159,26 +166,22 @@ void Actor::move(Actor::Movement direction) | |||
| 159 | if (direction == Actor::None) | 166 | if (direction == Actor::None) |
| 160 | m_images[m_direction]->setVisible(true); | 167 | m_images[m_direction]->setVisible(true); |
| 161 | else | 168 | else |
| 162 | { | ||
| 163 | m_eating[direction]->start(); | 169 | m_eating[direction]->start(); |
| 164 | } | ||
| 165 | m_direction = direction; | ||
| 166 | } | 170 | } |
| 167 | 171 | ||
| 168 | if (direction != Actor::None) | 172 | if (direction != Actor::None) |
| 169 | { | 173 | { |
| 170 | if (m_local && AudioPlayer::self()->state() != Phonon::PlayingState) | 174 | if (m_local && m_player->isWorking() && m_player->state() != Phonon::PlayingState) |
| 171 | { | 175 | m_player->play(); |
| 172 | AudioPlayer::self()->clear(); | ||
| 173 | AudioPlayer::self()->play(AudioPlayer::WakaWaka); | ||
| 174 | AudioPlayer::self()->enqueue(AudioPlayer::WakaWaka); | ||
| 175 | } | ||
| 176 | m_moving->start(); | 176 | m_moving->start(); |
| 177 | } | 177 | } |
| 178 | else | 178 | else if (direction != m_direction) |
| 179 | { | 179 | { |
| 180 | AudioPlayer::self()->stop(); | 180 | if (m_local && m_player->isWorking() && m_player->state() != Phonon::PausedState) |
| 181 | m_player->pause(); | ||
| 181 | } | 182 | } |
| 183 | |||
| 184 | m_direction = direction; | ||
| 182 | } | 185 | } |
| 183 | 186 | ||
| 184 | bool Actor::isMoving() | 187 | bool Actor::isMoving() |
| @@ -186,22 +189,16 @@ bool Actor::isMoving() | |||
| 186 | return (m_moving->state() == QAbstractAnimation::Running); | 189 | return (m_moving->state() == QAbstractAnimation::Running); |
| 187 | } | 190 | } |
| 188 | 191 | ||
| 189 | void Actor::enqueue() | ||
| 190 | { | ||
| 191 | if (isMoving()) | ||
| 192 | AudioPlayer::self()->enqueue(AudioPlayer::WakaWaka); | ||
| 193 | } | ||
| 194 | |||
| 195 | void Actor::die() | 192 | void Actor::die() |
| 196 | { | 193 | { |
| 197 | if (!m_local) | 194 | if (!m_local) |
| 198 | return; | 195 | return; |
| 199 | AudioPlayer::self()->play(AudioPlayer::Die); | 196 | AudioManager::self()->play(Sound::Die); |
| 200 | } | 197 | } |
| 201 | 198 | ||
| 202 | void Actor::eatingCherry() | 199 | void Actor::eatingCherry() |
| 203 | { | 200 | { |
| 204 | if (!m_local) | 201 | if (!m_local) |
| 205 | return; | 202 | return; |
| 206 | AudioPlayer::self()->play(AudioPlayer::EatingCherry); | 203 | AudioManager::self()->play(Sound::EatingCherry); |
| 207 | } | 204 | } |
