diff options
| -rw-r--r-- | pacman-c++/actor.cpp | 6 | ||||
| -rw-r--r-- | pacman-c++/actor.h | 1 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 5 | ||||
| -rw-r--r-- | pacman-c++/sceneholder.cpp | 46 | ||||
| -rw-r--r-- | pacman-c++/sceneholder.h | 2 | ||||
| -rw-r--r-- | pacman-c++/server.cpp | 4 |
6 files changed, 61 insertions, 3 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 757003e..de8d77e 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -57,7 +57,6 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | |||
| 57 | m_eating.append(setupEatingAnimation(Actor::Down)); | 57 | m_eating.append(setupEatingAnimation(Actor::Down)); |
| 58 | 58 | ||
| 59 | /* dieing animation */ | 59 | /* dieing animation */ |
| 60 | qWarning() << "color=" << Util::colorToString(m_color) << "zValue=" << zValue() << "dieing.z=" << 100 - m_color; | ||
| 61 | m_dieing = new QSequentialAnimationGroup(this); | 60 | m_dieing = new QSequentialAnimationGroup(this); |
| 62 | for (int i = 0; i < 11; i++) | 61 | for (int i = 0; i < 11; i++) |
| 63 | { | 62 | { |
| @@ -123,6 +122,11 @@ PixmapItem &Actor::icon() | |||
| 123 | return m_icon; | 122 | return m_icon; |
| 124 | } | 123 | } |
| 125 | 124 | ||
| 125 | const QString Actor::iconStr() | ||
| 126 | { | ||
| 127 | return QString(":/actor%1icon").arg(Util::floorLog2(m_color) + 1); | ||
| 128 | } | ||
| 129 | |||
| 126 | Actor::Movement Actor::direction() | 130 | Actor::Movement Actor::direction() |
| 127 | { | 131 | { |
| 128 | return m_direction; | 132 | return m_direction; |
diff --git a/pacman-c++/actor.h b/pacman-c++/actor.h index e7d3ebc..c30c62a 100644 --- a/pacman-c++/actor.h +++ b/pacman-c++/actor.h | |||
| @@ -33,6 +33,7 @@ public: | |||
| 33 | {}; | 33 | {}; |
| 34 | 34 | ||
| 35 | PixmapItem &icon(); | 35 | PixmapItem &icon(); |
| 36 | const QString iconStr(); | ||
| 36 | Movement direction(); | 37 | Movement direction(); |
| 37 | void setDirection(Movement direction); | 38 | void setDirection(Movement direction); |
| 38 | void reset(); | 39 | void reset(); |
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index 3c77765..93fd796 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include "constants.h" | 4 | #include "constants.h" |
| 5 | #include "util.h" | 5 | #include "util.h" |
| 6 | #include "pacman.pb.h" | 6 | #include "pacman.pb.h" |
| 7 | #include <QStringBuilder> | ||
| 7 | 8 | ||
| 8 | MainWidget::MainWidget(QWidget *parent) | 9 | MainWidget::MainWidget(QWidget *parent) |
| 9 | : QWidget(parent), m_currentKey(Transmission::none), m_running(false), m_scene(NULL), | 10 | : QWidget(parent), m_currentKey(Transmission::none), m_running(false), m_scene(NULL), |
| @@ -173,6 +174,9 @@ void MainWidget::tick() | |||
| 173 | m_scene->updateMap(map); | 174 | m_scene->updateMap(map); |
| 174 | Util::deleteMap(map); | 175 | Util::deleteMap(map); |
| 175 | updateScore(m_updatepacket); | 176 | updateScore(m_updatepacket); |
| 177 | |||
| 178 | if (m_updatepacket.eating_order_size() > 0) | ||
| 179 | m_scene->showEatingText(); | ||
| 176 | } | 180 | } |
| 177 | } | 181 | } |
| 178 | 182 | ||
| @@ -214,6 +218,7 @@ void MainWidget::keyReleaseEvent(QKeyEvent* event) | |||
| 214 | void MainWidget::startGame() | 218 | void MainWidget::startGame() |
| 215 | { | 219 | { |
| 216 | disconnect(AudioManager::self()->audioPlayer(), NULL, this, SLOT(startGame())); | 220 | disconnect(AudioManager::self()->audioPlayer(), NULL, this, SLOT(startGame())); |
| 221 | m_scene->showEatingText(false); | ||
| 217 | m_running = true; | 222 | m_running = true; |
| 218 | sendKeyUpdate(); | 223 | sendKeyUpdate(); |
| 219 | m_ambientPlayer->play(); | 224 | m_ambientPlayer->play(); |
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index f6b8145..51496ca 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp | |||
| @@ -13,6 +13,8 @@ SceneHolder::SceneHolder(QObject *parent) | |||
| 13 | setSceneRect(0, 0, Constants::map_size_pixel.width, Constants::map_size_pixel.height); | 13 | setSceneRect(0, 0, Constants::map_size_pixel.width, Constants::map_size_pixel.height); |
| 14 | setBackgroundBrush(Qt::black); | 14 | setBackgroundBrush(Qt::black); |
| 15 | 15 | ||
| 16 | m_overlayText = new QGraphicsTextItem(); | ||
| 17 | |||
| 16 | visualMap.resize(Constants::map_size.width); | 18 | visualMap.resize(Constants::map_size.width); |
| 17 | for (int i = 0; i < visualMap.size(); ++i) | 19 | for (int i = 0; i < visualMap.size(); ++i) |
| 18 | visualMap[i].resize(Constants::map_size.height); | 20 | visualMap[i].resize(Constants::map_size.height); |
| @@ -21,6 +23,7 @@ SceneHolder::SceneHolder(QObject *parent) | |||
| 21 | void SceneHolder::reset() | 23 | void SceneHolder::reset() |
| 22 | { | 24 | { |
| 23 | processDelayedItems(); | 25 | processDelayedItems(); |
| 26 | showEatingText(false); | ||
| 24 | 27 | ||
| 25 | /* remove actors from scene so they don't get deleted during clear */ | 28 | /* remove actors from scene so they don't get deleted during clear */ |
| 26 | foreach(Actor *actor, m_actors) | 29 | foreach(Actor *actor, m_actors) |
| @@ -269,6 +272,49 @@ QList<Color::Color> &SceneHolder::eatingOrder() | |||
| 269 | return m_eatingorder; | 272 | return m_eatingorder; |
| 270 | } | 273 | } |
| 271 | 274 | ||
| 275 | void SceneHolder::showEatingText(bool show) | ||
| 276 | { | ||
| 277 | if (!show) | ||
| 278 | { | ||
| 279 | if (m_overlayText->scene() == this) | ||
| 280 | removeItem(m_overlayText); | ||
| 281 | return; | ||
| 282 | } | ||
| 283 | |||
| 284 | m_overlayText->setDefaultTextColor(Qt::black); | ||
| 285 | QString text = QString( | ||
| 286 | "<div style=\"background-color: gray;\" align=\"center\">" | ||
| 287 | "<br />" | ||
| 288 | ); | ||
| 289 | unsigned int lines = 1; | ||
| 290 | |||
| 291 | text = text % QString("<b>Your Pacman: <img src=\"%1\"/></b><br /><br />") | ||
| 292 | .arg(m_actors[m_color]->iconStr()); | ||
| 293 | lines += 2; | ||
| 294 | |||
| 295 | foreach(Actor *actor, m_actors) | ||
| 296 | { | ||
| 297 | foreach(Actor *other, m_actors) | ||
| 298 | { | ||
| 299 | if (!actor->canEat(other, m_eatingorder)) | ||
| 300 | continue; | ||
| 301 | text = text % QString("<img src=\"%1\"/> can eat <img src=\"%2\"/><br />") | ||
| 302 | .arg(actor->iconStr(), other->iconStr()); | ||
| 303 | ++lines; | ||
| 304 | } | ||
| 305 | } | ||
| 306 | text = text % "</div>"; | ||
| 307 | m_overlayText->setHtml(text); | ||
| 308 | m_overlayText->setTextWidth(150); | ||
| 309 | m_overlayText->setOpacity(0.9); | ||
| 310 | |||
| 311 | QFontMetrics metrics(m_overlayText->font()); | ||
| 312 | m_overlayText->setPos((width() - m_overlayText->textWidth()) / 2, (height() - metrics.height() * lines) / 2); | ||
| 313 | m_overlayText->setZValue(100); | ||
| 314 | |||
| 315 | addItem(m_overlayText); | ||
| 316 | } | ||
| 317 | |||
| 272 | QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) | 318 | QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) |
| 273 | { | 319 | { |
| 274 | return QPoint(x * Constants::field_size.width, y * Constants::field_size.height); | 320 | return QPoint(x * Constants::field_size.width, y * Constants::field_size.height); |
diff --git a/pacman-c++/sceneholder.h b/pacman-c++/sceneholder.h index dcc10bf..7d6e556 100644 --- a/pacman-c++/sceneholder.h +++ b/pacman-c++/sceneholder.h | |||
| @@ -24,6 +24,7 @@ public: | |||
| 24 | Color::Color color(); | 24 | Color::Color color(); |
| 25 | void setEatingOrder(QList<Color::Color> &order); | 25 | void setEatingOrder(QList<Color::Color> &order); |
| 26 | QList<Color::Color> &eatingOrder(); | 26 | QList<Color::Color> &eatingOrder(); |
| 27 | void showEatingText(bool show = true); | ||
| 27 | 28 | ||
| 28 | signals: | 29 | signals: |
| 29 | void allPointsRemoved(); | 30 | void allPointsRemoved(); |
| @@ -66,6 +67,7 @@ protected: | |||
| 66 | 67 | ||
| 67 | /* points left before round ends */ | 68 | /* points left before round ends */ |
| 68 | unsigned int m_pointsLeft; | 69 | unsigned int m_pointsLeft; |
| 70 | QGraphicsTextItem *m_overlayText; | ||
| 69 | }; | 71 | }; |
| 70 | 72 | ||
| 71 | #endif // SCENEHOLDER_H | 73 | #endif // SCENEHOLDER_H |
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index caf2fa5..962d1bf 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -22,7 +22,7 @@ Server::Server(QWidget *parent) | |||
| 22 | bool Server::run() | 22 | bool Server::run() |
| 23 | { | 23 | { |
| 24 | /* create eating order list first - this can also be created dynamically per round (theoretically) */ | 24 | /* create eating order list first - this can also be created dynamically per round (theoretically) */ |
| 25 | for(unsigned i = 0; i < m_maxplayers; ++i) | 25 | for(unsigned int i = 0; i < m_maxplayers; ++i) |
| 26 | m_eatingorder.append(Color::order[i]); | 26 | m_eatingorder.append(Color::order[i]); |
| 27 | m_eatingorder.append(Color::order[0]); | 27 | m_eatingorder.append(Color::order[0]); |
| 28 | 28 | ||
| @@ -406,7 +406,7 @@ void Server::sendUpdate(Transmission::map_t map, bool firstPacket) | |||
| 406 | m_updatepacket.add_field(map[x][y]); | 406 | m_updatepacket.add_field(map[x][y]); |
| 407 | } | 407 | } |
| 408 | 408 | ||
| 409 | for(unsigned i = 0; i < m_maxplayers; ++i) | 409 | for(unsigned int i = 0; i < m_maxplayers; ++i) |
| 410 | { | 410 | { |
| 411 | m_updatepacket.add_round_points(m_actors.value(Color::order[i])->getRoundPoints()); | 411 | m_updatepacket.add_round_points(m_actors.value(Color::order[i])->getRoundPoints()); |
| 412 | m_updatepacket.add_game_points(m_actors.value(Color::order[i])->getGamePoints()); | 412 | m_updatepacket.add_game_points(m_actors.value(Color::order[i])->getGamePoints()); |
