diff options
| author | manuel <manuel@mausz.at> | 2011-04-12 16:22:19 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-12 16:22:19 +0200 |
| commit | fae7c3377c8995b217e620c5cf1e963b3ab1e84a (patch) | |
| tree | 61a091e2799dda061c227be54c39a61a7b83daca | |
| parent | dbeba838ea813b620ec571265c8ea417403fc81c (diff) | |
| download | foop-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
| -rw-r--r-- | pacman-c++/actor.cpp | 93 | ||||
| -rw-r--r-- | pacman-c++/actor.h | 3 | ||||
| -rw-r--r-- | pacman-c++/point.cpp | 8 | ||||
| -rw-r--r-- | pacman-c++/sceneholder.cpp | 26 | ||||
| -rw-r--r-- | pacman-c++/server.cpp | 5 |
5 files changed, 81 insertions, 54 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 | ||
| 12 | Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | 12 | Actor::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 | |||
| 203 | void 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 | ||
| 251 | AudioPlayer *Actor::wakaPlayer() | ||
| 252 | { | ||
| 253 | if (!m_local || !m_wakaPlayer->isWorking()) | ||
| 254 | return NULL; | ||
| 255 | return m_wakaPlayer; | ||
| 256 | } | ||
| 257 | |||
| 216 | unsigned int Actor::getRoundPoints() | 258 | unsigned 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 | |||
| 237 | void 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 | } | ||
diff --git a/pacman-c++/actor.h b/pacman-c++/actor.h index d1875f1..ae04687 100644 --- a/pacman-c++/actor.h +++ b/pacman-c++/actor.h | |||
| @@ -35,6 +35,7 @@ public: | |||
| 35 | bool isMoving(); | 35 | bool isMoving(); |
| 36 | void die(); | 36 | void die(); |
| 37 | void eatingCherry(); | 37 | void eatingCherry(); |
| 38 | AudioPlayer *wakaPlayer(); | ||
| 38 | 39 | ||
| 39 | unsigned int getRoundPoints(); | 40 | unsigned int getRoundPoints(); |
| 40 | unsigned int getGamePoints(); | 41 | unsigned int getGamePoints(); |
| @@ -50,7 +51,7 @@ private: | |||
| 50 | Movement m_direction; | 51 | Movement m_direction; |
| 51 | PixmapItem m_icon; | 52 | PixmapItem m_icon; |
| 52 | bool m_local; | 53 | bool m_local; |
| 53 | AudioPlayer *m_player; | 54 | AudioPlayer *m_wakaPlayer; |
| 54 | 55 | ||
| 55 | unsigned int m_roundPoints; | 56 | unsigned int m_roundPoints; |
| 56 | unsigned int m_gamePoints; | 57 | unsigned int m_gamePoints; |
diff --git a/pacman-c++/point.cpp b/pacman-c++/point.cpp index 35266f6..54c0ee4 100644 --- a/pacman-c++/point.cpp +++ b/pacman-c++/point.cpp | |||
| @@ -28,5 +28,11 @@ bool Point::enter(Actor *actor) | |||
| 28 | 28 | ||
| 29 | void Point::onDie(Actor *actor) | 29 | void Point::onDie(Actor *actor) |
| 30 | { | 30 | { |
| 31 | //TODO | 31 | AudioPlayer *player = actor->wakaPlayer(); |
| 32 | qDebug() << "onDie" << player; | ||
| 33 | if (player == NULL) | ||
| 34 | return; | ||
| 35 | if (player->state() != Phonon::PlayingState) | ||
| 36 | player->play(); | ||
| 37 | player->setMuted(false); | ||
| 32 | } | 38 | } |
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index b788a49..fc638f7 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp | |||
| @@ -33,25 +33,28 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 33 | 33 | ||
| 34 | if (cur & Transmission::empty) | 34 | if (cur & Transmission::empty) |
| 35 | { | 35 | { |
| 36 | /* special handling for purging field */ | ||
| 37 | PixmapItem *oldItem = visualMap[x][y]; | 36 | PixmapItem *oldItem = visualMap[x][y]; |
| 38 | /* remove elements (in case it's not an actor) */ | 37 | /* special handling for purging field |
| 39 | if (oldItem != NULL && dynamic_cast<Actor *>(item) == NULL) | 38 | * remove elements (in case it's not an actor) |
| 39 | */ | ||
| 40 | if (oldItem != NULL && dynamic_cast<Actor *>(oldItem) == NULL) | ||
| 40 | { | 41 | { |
| 41 | removeItem(oldItem); | 42 | removeItem(oldItem); |
| 42 | visualMap[x][y] = NULL; | 43 | visualMap[x][y] = NULL; |
| 43 | Actor *actor = NULL; | 44 | Actor *actor = NULL; |
| 44 | foreach (Actor *i, m_actors) | 45 | foreach (Actor *tmp, m_actors) |
| 45 | { | 46 | { |
| 46 | if (CoordToMapPosition(i->pos().toPoint()) == QPoint(x, y)) | 47 | if (cur & tmp->color()) |
| 47 | { | 48 | { |
| 48 | actor = i; | 49 | actor = tmp; |
| 49 | break; | 50 | break; |
| 50 | } | 51 | } |
| 51 | } | 52 | } |
| 53 | |||
| 54 | /* no actor removed that item */ | ||
| 55 | if (actor == NULL) | ||
| 56 | Q_ASSERT(false); | ||
| 52 | oldItem->onDie(actor); | 57 | oldItem->onDie(actor); |
| 53 | delete oldItem; | ||
| 54 | //qDebug() << "deleting " << x << y; | ||
| 55 | } | 58 | } |
| 56 | } | 59 | } |
| 57 | 60 | ||
| @@ -112,11 +115,14 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 112 | Q_ASSERT(false); | 115 | Q_ASSERT(false); |
| 113 | } | 116 | } |
| 114 | 117 | ||
| 118 | /* add new created item to scene | ||
| 119 | * remove old item on that location if there's one | ||
| 120 | */ | ||
| 115 | if (item != NULL) | 121 | if (item != NULL) |
| 116 | { | 122 | { |
| 117 | addItem(item); | 123 | addItem(item); |
| 118 | item->setPos(mapPositionToCoord(x, y)); | 124 | item->setPos(mapPositionToCoord(x, y)); |
| 119 | PixmapItem* oldItem = visualMap[x][y]; | 125 | PixmapItem *oldItem = visualMap[x][y]; |
| 120 | visualMap[x][y] = item; | 126 | visualMap[x][y] = item; |
| 121 | if (oldItem != NULL) | 127 | if (oldItem != NULL) |
| 122 | { | 128 | { |
| @@ -126,7 +132,6 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 126 | } | 132 | } |
| 127 | } | 133 | } |
| 128 | } | 134 | } |
| 129 | |||
| 130 | } | 135 | } |
| 131 | 136 | ||
| 132 | void SceneHolder::setColor(Color::Color color) | 137 | void SceneHolder::setColor(Color::Color color) |
| @@ -147,7 +152,6 @@ unsigned int SceneHolder::pointsLeft() | |||
| 147 | void SceneHolder::decrementPoints() | 152 | void SceneHolder::decrementPoints() |
| 148 | { | 153 | { |
| 149 | --m_pointsLeft; | 154 | --m_pointsLeft; |
| 150 | qDebug() << "points left=" << m_pointsLeft; | ||
| 151 | } | 155 | } |
| 152 | 156 | ||
| 153 | QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) | 157 | QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) |
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 9a7b188..b0ac6f8 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -87,8 +87,11 @@ invalid_direction: | |||
| 87 | PixmapItem *oldItem = visualMap[mapPosition.x()][mapPosition.y()]; | 87 | PixmapItem *oldItem = visualMap[mapPosition.x()][mapPosition.y()]; |
| 88 | if (oldItem != NULL) | 88 | if (oldItem != NULL) |
| 89 | { | 89 | { |
| 90 | /* set item to explicit empty | ||
| 91 | * and add actor that removed/has eaten that item | ||
| 92 | */ | ||
| 90 | if (oldItem->eaten()) | 93 | if (oldItem->eaten()) |
| 91 | map[mapPosition.x()][mapPosition.y()] = Transmission::empty; | 94 | map[mapPosition.x()][mapPosition.y()] = Transmission::empty | actor->color(); |
| 92 | } | 95 | } |
| 93 | 96 | ||
| 94 | // new item | 97 | // new item |
