summaryrefslogtreecommitdiffstats
path: root/pacman-c++/actor.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-12 16:22:19 +0200
committermanuel <manuel@mausz.at>2011-04-12 16:22:19 +0200
commitfae7c3377c8995b217e620c5cf1e963b3ab1e84a (patch)
tree61a091e2799dda061c227be54c39a61a7b83daca /pacman-c++/actor.cpp
parentdbeba838ea813b620ec571265c8ea417403fc81c (diff)
downloadfoop-fae7c3377c8995b217e620c5cf1e963b3ab1e84a.tar.gz
foop-fae7c3377c8995b217e620c5cf1e963b3ab1e84a.tar.bz2
foop-fae7c3377c8995b217e620c5cf1e963b3ab1e84a.zip
finding out which actor has eaten which element didn't work correctly. instead of checking that on client side the server now just sends the id of the actor withing the explicit empty id data field
Diffstat (limited to 'pacman-c++/actor.cpp')
-rw-r--r--pacman-c++/actor.cpp93
1 files changed, 53 insertions, 40 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp
index baf6dca..41de160 100644
--- a/pacman-c++/actor.cpp
+++ b/pacman-c++/actor.cpp
@@ -11,7 +11,7 @@ static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal
11 11
12Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) 12Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent)
13 : 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),
14 m_player(NULL), m_roundPoints(0), m_gamePoints(0) 14 m_wakaPlayer(NULL), m_roundPoints(0), m_gamePoints(0)
15{ 15{
16 /* DON'T set any pixmap here. we've a pixmap in the animation 16 /* DON'T set any pixmap here. we've a pixmap in the animation
17 * but we need a sprite for the collision detection 17 * but we need a sprite for the collision detection
@@ -55,14 +55,14 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent)
55 m_eating.append(setupEatingAnimation(Actor::Up)); 55 m_eating.append(setupEatingAnimation(Actor::Up));
56 m_eating.append(setupEatingAnimation(Actor::Down)); 56 m_eating.append(setupEatingAnimation(Actor::Down));
57 57
58 /* setup sound */ 58 /* setup waka sound */
59 if (local) 59 if (local)
60 { 60 {
61 m_player = new AudioPlayer(this); 61 m_wakaPlayer = new AudioPlayer(this);
62 if (m_player->isWorking()) 62 if (m_wakaPlayer->isWorking())
63 { 63 {
64 m_player->setLoop(Sound::WakaWaka); 64 m_wakaPlayer->setLoop(Sound::WakaWaka);
65 AudioManager::self()->registerAudioPlayer(m_player); 65 AudioManager::self()->registerAudioPlayer(m_wakaPlayer);
66 } 66 }
67 } 67 }
68 68
@@ -95,7 +95,7 @@ QSequentialAnimationGroup *Actor::setupEatingAnimation(Actor::Movement direction
95 fadeout->setEndValue(false); 95 fadeout->setEndValue(false);
96 96
97 QPropertyAnimation *move = new QPropertyAnimation(img, "pos", m_moving); 97 QPropertyAnimation *move = new QPropertyAnimation(img, "pos", m_moving);
98 move->setDuration(Constants::tick - 30); //TODO 98 move->setDuration(Constants::tick - 30);
99 move->setEndValue(QPoint(0, 0)); 99 move->setEndValue(QPoint(0, 0));
100 } 100 }
101 101
@@ -181,16 +181,51 @@ void Actor::move(Actor::Movement direction)
181 181
182 if (direction != Actor::None) 182 if (direction != Actor::None)
183 { 183 {
184 if (m_local && m_player->isWorking() && m_player->state() != Phonon::PlayingState) 184 //if (m_local && m_player->isWorking() && m_player->state() != Phonon::PlayingState)
185 m_player->play(); 185 // m_player->play();
186 m_moving->start(); 186 m_moving->start();
187 } 187 }
188 else if (direction != m_direction) 188 else if (direction != m_direction)
189 { 189 {
190 if (m_local && m_player->isWorking() && m_player->state() != Phonon::PausedState) 190 //if (m_local && m_player->isWorking() && m_player->state() != Phonon::PausedState)
191 m_player->pause(); 191 // m_player->pause();
192 } 192 }
193 193
194 if (direction == Actor::None)
195 {
196 qDebug() << "pause";
197 m_wakaPlayer->setMuted(true);
198 }
199
200 m_direction = direction;
201}
202
203void Actor::moveByServer(Actor::Movement direction)
204{
205 qDebug() << "move by server";
206
207 QPointF endpos(0, 0);
208 switch(direction)
209 {
210 case Actor::None:
211 break;
212 case Actor::Left:
213 endpos.setX(static_cast<qreal>(Constants::field_size.width) * -1);
214 break;
215 case Actor::Right:
216 endpos.setX(Constants::field_size.width);
217 break;
218 case Actor::Up:
219 endpos.setY(static_cast<qreal>(Constants::field_size.height) * -1);
220 break;
221 case Actor::Down:
222 endpos.setY(Constants::field_size.height);
223 break;
224 default:
225 Q_ASSERT(false);
226 break;
227 }
228 setPos(pos() + endpos);
194 m_direction = direction; 229 m_direction = direction;
195} 230}
196 231
@@ -213,6 +248,13 @@ void Actor::eatingCherry()
213 AudioManager::self()->play(Sound::EatingCherry); 248 AudioManager::self()->play(Sound::EatingCherry);
214} 249}
215 250
251AudioPlayer *Actor::wakaPlayer()
252{
253 if (!m_local || !m_wakaPlayer->isWorking())
254 return NULL;
255 return m_wakaPlayer;
256}
257
216unsigned int Actor::getRoundPoints() 258unsigned int Actor::getRoundPoints()
217{ 259{
218 return m_roundPoints; 260 return m_roundPoints;
@@ -233,32 +275,3 @@ void Actor::finishRound()
233 m_gamePoints += m_roundPoints; 275 m_gamePoints += m_roundPoints;
234 m_roundPoints = 0; 276 m_roundPoints = 0;
235} 277}
236
237void Actor::moveByServer(Actor::Movement direction)
238{
239 qDebug() << "move by server";
240
241 QPointF endpos(0, 0);
242 switch(direction)
243 {
244 case Actor::None:
245 break;
246 case Actor::Left:
247 endpos.setX(static_cast<qreal>(Constants::field_size.width) * -1);
248 break;
249 case Actor::Right:
250 endpos.setX(Constants::field_size.width);
251 break;
252 case Actor::Up:
253 endpos.setY(static_cast<qreal>(Constants::field_size.height) * -1);
254 break;
255 case Actor::Down:
256 endpos.setY(Constants::field_size.height);
257 break;
258 default:
259 Q_ASSERT(false);
260 break;
261 }
262 setPos(pos() + endpos);
263 m_direction = direction;
264}