summaryrefslogtreecommitdiffstats
path: root/pacman-c++
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-05-02 20:42:37 +0200
committermanuel <manuel@mausz.at>2011-05-02 20:42:37 +0200
commit0c4d6493ce9d1215c10d5f2942d373c4f37204b5 (patch)
tree5bd36abfe2ecb65d2c453ff88359cdda561f094b /pacman-c++
parent6ca702032d6844e211c67f18cf066e34fbbaf9d0 (diff)
downloadfoop-0c4d6493ce9d1215c10d5f2942d373c4f37204b5.tar.gz
foop-0c4d6493ce9d1215c10d5f2942d373c4f37204b5.tar.bz2
foop-0c4d6493ce9d1215c10d5f2942d373c4f37204b5.zip
add eating overlay
Diffstat (limited to 'pacman-c++')
-rw-r--r--pacman-c++/actor.cpp6
-rw-r--r--pacman-c++/actor.h1
-rw-r--r--pacman-c++/mainwidget.cpp5
-rw-r--r--pacman-c++/sceneholder.cpp46
-rw-r--r--pacman-c++/sceneholder.h2
-rw-r--r--pacman-c++/server.cpp4
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
125const QString Actor::iconStr()
126{
127 return QString(":/actor%1icon").arg(Util::floorLog2(m_color) + 1);
128}
129
126Actor::Movement Actor::direction() 130Actor::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
8MainWidget::MainWidget(QWidget *parent) 9MainWidget::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)
214void MainWidget::startGame() 218void 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)
21void SceneHolder::reset() 23void 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
275void 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\"/> &nbsp;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
272QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) 318QPoint 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
28signals: 29signals:
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)
22bool Server::run() 22bool 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());