diff options
Diffstat (limited to 'pacman-c++/actor.cpp')
| -rw-r--r-- | pacman-c++/actor.cpp | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index b6de49c..7358756 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | #include "animationmanager.h" | 2 | #include "animationmanager.h" |
| 3 | #include <QtCore/QPropertyAnimation> | 3 | #include <QtCore/QPropertyAnimation> |
| 4 | #include <QtCore/QVariantAnimation> | 4 | #include <QtCore/QVariantAnimation> |
| 5 | #include <phonon/AudioOutput> | ||
| 5 | #include <QDebug> | 6 | #include <QDebug> |
| 6 | 7 | ||
| 7 | static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal progress) | 8 | static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal progress) |
| @@ -13,9 +14,8 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | |||
| 13 | : PixmapItem(parent), m_color(color), m_direction(Actor::None), m_local(local) | 14 | : PixmapItem(parent), m_color(color), m_direction(Actor::None), m_local(local) |
| 14 | { | 15 | { |
| 15 | m_pix = ":/" + QString("actor%1").arg((m_color >> 1) + 1); | 16 | m_pix = ":/" + QString("actor%1").arg((m_color >> 1) + 1); |
| 16 | // 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 */ |
| 17 | //setPixmap(m_pix); | 18 | /* higher player "over" lower player */ |
| 18 | // higher player "over" lower player | ||
| 19 | setZValue(m_color * 10); | 19 | setZValue(m_color * 10); |
| 20 | 20 | ||
| 21 | /* setup icon for player */ | 21 | /* setup icon for player */ |
| @@ -46,6 +46,17 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | |||
| 46 | m_eating.append(setupEatingAnimation(Actor::Up)); | 46 | m_eating.append(setupEatingAnimation(Actor::Up)); |
| 47 | m_eating.append(setupEatingAnimation(Actor::Down)); | 47 | m_eating.append(setupEatingAnimation(Actor::Down)); |
| 48 | 48 | ||
| 49 | /* setup player */ | ||
| 50 | m_player = new Phonon::MediaObject(this); | ||
| 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 | |||
| 49 | /* make the picture showing the current direction visible */ | 60 | /* make the picture showing the current direction visible */ |
| 50 | m_images[m_direction]->setVisible(true); | 61 | m_images[m_direction]->setVisible(true); |
| 51 | } | 62 | } |
| @@ -103,6 +114,13 @@ void Actor::move(Actor::Movement direction) | |||
| 103 | if (isMoving()) | 114 | if (isMoving()) |
| 104 | return; | 115 | return; |
| 105 | 116 | ||
| 117 | if (m_local && m_player->state() != Phonon::PlayingState) | ||
| 118 | { | ||
| 119 | m_player->stop(); | ||
| 120 | m_player->setCurrentSource(m_sounds[0]); | ||
| 121 | m_player->play(); | ||
| 122 | } | ||
| 123 | |||
| 106 | /* stop current animation */ | 124 | /* stop current animation */ |
| 107 | if (direction != m_direction) | 125 | if (direction != m_direction) |
| 108 | { | 126 | { |
| @@ -162,3 +180,27 @@ bool Actor::isMoving() | |||
| 162 | { | 180 | { |
| 163 | return (m_moving->state() == QAbstractAnimation::Running); | 181 | return (m_moving->state() == QAbstractAnimation::Running); |
| 164 | } | 182 | } |
| 183 | |||
| 184 | void Actor::enqueue() | ||
| 185 | { | ||
| 186 | if (isMoving()) | ||
| 187 | m_player->enqueue(m_sounds[0]); | ||
| 188 | } | ||
| 189 | |||
| 190 | void Actor::die() | ||
| 191 | { | ||
| 192 | if (!m_local) | ||
| 193 | return; | ||
| 194 | m_player->stop(); | ||
| 195 | m_player->setCurrentSource(m_sounds[1]); | ||
| 196 | m_player->play(); | ||
| 197 | } | ||
| 198 | |||
| 199 | void Actor::eatingCherry() | ||
| 200 | { | ||
| 201 | if (!m_local) | ||
| 202 | return; | ||
| 203 | m_player->stop(); | ||
| 204 | m_player->setCurrentSource(m_sounds[2]); | ||
| 205 | m_player->play(); | ||
| 206 | } | ||
