summaryrefslogtreecommitdiffstats
path: root/pacman-c++
diff options
context:
space:
mode:
Diffstat (limited to 'pacman-c++')
-rw-r--r--pacman-c++/actor.cpp9
-rw-r--r--pacman-c++/actor.h6
-rw-r--r--pacman-c++/block.cpp2
-rw-r--r--pacman-c++/block.h4
-rw-r--r--pacman-c++/bonuspoint.cpp2
-rw-r--r--pacman-c++/bonuspoint.h4
-rw-r--r--pacman-c++/gameentity.cpp11
-rw-r--r--pacman-c++/gameentity.h14
-rw-r--r--pacman-c++/mainwidget.cpp4
-rw-r--r--pacman-c++/pixmapitem.h3
-rw-r--r--pacman-c++/point.cpp3
-rw-r--r--pacman-c++/point.h4
-rw-r--r--pacman-c++/sceneholder.cpp26
-rw-r--r--pacman-c++/sceneholder.h9
-rw-r--r--pacman-c++/server.cpp23
15 files changed, 70 insertions, 54 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp
index 41de160..d53566e 100644
--- a/pacman-c++/actor.cpp
+++ b/pacman-c++/actor.cpp
@@ -10,7 +10,7 @@ static QVariant myBooleanInterpolator(const bool &start, const bool &end, qreal
10} 10}
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 : GameEntity(color, parent),m_direction(Actor::None), m_local(local),
14 m_wakaPlayer(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
@@ -102,11 +102,6 @@ QSequentialAnimationGroup *Actor::setupEatingAnimation(Actor::Movement direction
102 return eating; 102 return eating;
103} 103}
104 104
105Color::Color Actor::color()
106{
107 return m_color;
108}
109
110PixmapItem &Actor::icon() 105PixmapItem &Actor::icon()
111{ 106{
112 return m_icon; 107 return m_icon;
@@ -194,7 +189,7 @@ void Actor::move(Actor::Movement direction)
194 if (direction == Actor::None) 189 if (direction == Actor::None)
195 { 190 {
196 qDebug() << "pause"; 191 qDebug() << "pause";
197 m_wakaPlayer->setMuted(true); 192 m_wakaPlayer->pause();
198 } 193 }
199 194
200 m_direction = direction; 195 m_direction = direction;
diff --git a/pacman-c++/actor.h b/pacman-c++/actor.h
index ae04687..6b6f743 100644
--- a/pacman-c++/actor.h
+++ b/pacman-c++/actor.h
@@ -1,7 +1,7 @@
1#ifndef ACTOR_H 1#ifndef ACTOR_H
2#define ACTOR_H 2#define ACTOR_H
3 3
4#include "pixmapitem.h" 4#include "gameentity.h"
5#include "constants.h" 5#include "constants.h"
6#include "audio.h" 6#include "audio.h"
7#include <QtCore/QSequentialAnimationGroup> 7#include <QtCore/QSequentialAnimationGroup>
@@ -9,7 +9,7 @@
9#include <QList> 9#include <QList>
10 10
11class Actor 11class Actor
12 : public PixmapItem 12 : public GameEntity
13{ 13{
14Q_OBJECT 14Q_OBJECT
15 15
@@ -27,7 +27,6 @@ public:
27 {}; 27 {};
28 28
29 QSequentialAnimationGroup *setupEatingAnimation(Actor::Movement direction); 29 QSequentialAnimationGroup *setupEatingAnimation(Actor::Movement direction);
30 Color::Color color();
31 PixmapItem &icon(); 30 PixmapItem &icon();
32 Movement direction(); 31 Movement direction();
33 bool isLocal(); 32 bool isLocal();
@@ -47,7 +46,6 @@ private:
47 46
48private: 47private:
49 QPixmap m_pix; 48 QPixmap m_pix;
50 Color::Color m_color;
51 Movement m_direction; 49 Movement m_direction;
52 PixmapItem m_icon; 50 PixmapItem m_icon;
53 bool m_local; 51 bool m_local;
diff --git a/pacman-c++/block.cpp b/pacman-c++/block.cpp
index b1ce0e0..c8607ac 100644
--- a/pacman-c++/block.cpp
+++ b/pacman-c++/block.cpp
@@ -5,7 +5,7 @@
5QMap<Color::Color, QPixmap> Block::m_pixmaps; 5QMap<Color::Color, QPixmap> Block::m_pixmaps;
6 6
7Block::Block(Color::Color color, unsigned int neighbours, QGraphicsItem *parent) 7Block::Block(Color::Color color, unsigned int neighbours, QGraphicsItem *parent)
8 : PixmapItem(parent) 8 : GameEntity(color, parent)
9{ 9{
10 /* empty object for servers */ 10 /* empty object for servers */
11 if (Constants::server) 11 if (Constants::server)
diff --git a/pacman-c++/block.h b/pacman-c++/block.h
index 9e49a7d..db104e3 100644
--- a/pacman-c++/block.h
+++ b/pacman-c++/block.h
@@ -1,12 +1,12 @@
1#ifndef BLOCK_H 1#ifndef BLOCK_H
2#define BLOCK_H 2#define BLOCK_H
3 3
4#include "pixmapitem.h" 4#include "gameentity.h"
5#include "constants.h" 5#include "constants.h"
6#include <QMap> 6#include <QMap>
7 7
8class Block 8class Block
9 : public PixmapItem 9 : public GameEntity
10{ 10{
11public: 11public:
12 enum Neighbour 12 enum Neighbour
diff --git a/pacman-c++/bonuspoint.cpp b/pacman-c++/bonuspoint.cpp
index bbb26b7..5bb470e 100644
--- a/pacman-c++/bonuspoint.cpp
+++ b/pacman-c++/bonuspoint.cpp
@@ -10,7 +10,7 @@ namespace
10} 10}
11 11
12BonusPoint::BonusPoint(QGraphicsItem *parent) 12BonusPoint::BonusPoint(QGraphicsItem *parent)
13 : PixmapItem(parent) 13 : GameEntity(parent)
14{ 14{
15 /* empty object for servers */ 15 /* empty object for servers */
16 if (Constants::server) 16 if (Constants::server)
diff --git a/pacman-c++/bonuspoint.h b/pacman-c++/bonuspoint.h
index 222e046..2c5a07d 100644
--- a/pacman-c++/bonuspoint.h
+++ b/pacman-c++/bonuspoint.h
@@ -1,10 +1,10 @@
1#ifndef BONUSPOINT_H 1#ifndef BONUSPOINT_H
2#define BONUSPOINT_H 2#define BONUSPOINT_H
3 3
4#include "pixmapitem.h" 4#include "gameentity.h"
5 5
6class BonusPoint 6class BonusPoint
7 : public PixmapItem 7 : public GameEntity
8{ 8{
9public: 9public:
10 BonusPoint(QGraphicsItem *parent=0); 10 BonusPoint(QGraphicsItem *parent=0);
diff --git a/pacman-c++/gameentity.cpp b/pacman-c++/gameentity.cpp
index 8711ebe..9dc72ec 100644
--- a/pacman-c++/gameentity.cpp
+++ b/pacman-c++/gameentity.cpp
@@ -1,6 +1,9 @@
1#include "gameentity.h" 1#include "gameentity.h"
2 2
3GameEntity::GameEntity() 3GameEntity::GameEntity(Color::Color color, QGraphicsItem *parent)
4 : m_eaten(false) 4 : PixmapItem(parent), m_eaten(false), m_color(color)
5{ 5{}
6} 6
7GameEntity::GameEntity(QGraphicsItem *parent)
8 : PixmapItem(parent), m_eaten(false), m_color(Color::none)
9{}
diff --git a/pacman-c++/gameentity.h b/pacman-c++/gameentity.h
index afa3aba..2fde095 100644
--- a/pacman-c++/gameentity.h
+++ b/pacman-c++/gameentity.h
@@ -1,6 +1,8 @@
1#ifndef GAMEENTITY_H 1#ifndef GAMEENTITY_H
2#define GAMEENTITY_H 2#define GAMEENTITY_H
3 3
4#include "constants.h"
5#include "pixmapitem.h"
4#include <QtGlobal> 6#include <QtGlobal>
5 7
6class Actor; 8class Actor;
@@ -9,12 +11,20 @@ class Actor;
9 * Base class for entities that interact in the game 11 * Base class for entities that interact in the game
10 */ 12 */
11class GameEntity 13class GameEntity
14 : public PixmapItem
12{ 15{
13public: 16public:
14 GameEntity(); 17 GameEntity(Color::Color color = Color::none, QGraphicsItem *parent = 0);
18 GameEntity(QGraphicsItem *parent);
15 virtual ~GameEntity() 19 virtual ~GameEntity()
16 {}; 20 {};
17 21
22 /* color of entity */
23 virtual Color::Color color()
24 {
25 return m_color;
26 }
27
18 /* returns whether the actor may enter this field */ 28 /* returns whether the actor may enter this field */
19 virtual bool checkEnter(Actor *) 29 virtual bool checkEnter(Actor *)
20 { 30 {
@@ -42,9 +52,9 @@ public:
42 virtual void onDie(Actor *) 52 virtual void onDie(Actor *)
43 {}; 53 {};
44 54
45
46protected: 55protected:
47 bool m_eaten; 56 bool m_eaten;
57 Color::Color m_color;
48}; 58};
49 59
50#endif // GAMEENTITY_H 60#endif // GAMEENTITY_H
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp
index 028bfad..ba09f7d 100644
--- a/pacman-c++/mainwidget.cpp
+++ b/pacman-c++/mainwidget.cpp
@@ -96,10 +96,10 @@ void MainWidget::updateScore(const ProtoBuf::MapUpdate& packet)
96 for(unsigned i = 0; Color::order[i] != Color::none; ++i) 96 for(unsigned i = 0; Color::order[i] != Color::none; ++i)
97 { 97 {
98 QGridLayout *score = m_playerScoreLayouts.at(i); 98 QGridLayout *score = m_playerScoreLayouts.at(i);
99 QLabel *turnPointsLbl = dynamic_cast<QLabel*>(score->itemAtPosition(0, 1)->widget()); 99 QLabel *turnPointsLbl = dynamic_cast<QLabel *>(score->itemAtPosition(0, 1)->widget());
100 turnPointsLbl->setText(QString::number(packet.round_points(i))); 100 turnPointsLbl->setText(QString::number(packet.round_points(i)));
101 101
102 QLabel *allPointsLbl = dynamic_cast<QLabel*>(score->itemAtPosition(1, 1)->widget()); 102 QLabel *allPointsLbl = dynamic_cast<QLabel *>(score->itemAtPosition(1, 1)->widget());
103 allPointsLbl->setText(QString::number(packet.round_points(i))); 103 allPointsLbl->setText(QString::number(packet.round_points(i)));
104 } 104 }
105} 105}
diff --git a/pacman-c++/pixmapitem.h b/pacman-c++/pixmapitem.h
index 7560556..f57c22a 100644
--- a/pacman-c++/pixmapitem.h
+++ b/pacman-c++/pixmapitem.h
@@ -1,12 +1,11 @@
1#ifndef PIXMAPITEM__H 1#ifndef PIXMAPITEM__H
2#define PIXMAPITEM__H 2#define PIXMAPITEM__H
3 3
4#include "gameentity.h"
5#include <QtGui/QGraphicsObject> 4#include <QtGui/QGraphicsObject>
6#include <QtGui/QGraphicsScene> 5#include <QtGui/QGraphicsScene>
7 6
8class PixmapItem 7class PixmapItem
9 : public QGraphicsObject, public GameEntity 8 : public QGraphicsObject
10{ 9{
11public: 10public:
12 PixmapItem(QGraphicsItem *parent = 0); 11 PixmapItem(QGraphicsItem *parent = 0);
diff --git a/pacman-c++/point.cpp b/pacman-c++/point.cpp
index 54c0ee4..1943756 100644
--- a/pacman-c++/point.cpp
+++ b/pacman-c++/point.cpp
@@ -8,7 +8,7 @@ namespace
8} 8}
9 9
10Point::Point(QGraphicsItem *parent) 10Point::Point(QGraphicsItem *parent)
11 : PixmapItem(parent) 11 : GameEntity(parent)
12{ 12{
13 /* empty object for servers */ 13 /* empty object for servers */
14 if (Constants::server) 14 if (Constants::server)
@@ -34,5 +34,4 @@ void Point::onDie(Actor *actor)
34 return; 34 return;
35 if (player->state() != Phonon::PlayingState) 35 if (player->state() != Phonon::PlayingState)
36 player->play(); 36 player->play();
37 player->setMuted(false);
38} 37}
diff --git a/pacman-c++/point.h b/pacman-c++/point.h
index 944764b..9fd9929 100644
--- a/pacman-c++/point.h
+++ b/pacman-c++/point.h
@@ -1,10 +1,10 @@
1#ifndef POINT_H 1#ifndef POINT_H
2#define POINT_H 2#define POINT_H
3 3
4#include "pixmapitem.h" 4#include "gameentity.h"
5 5
6class Point 6class Point
7 : public PixmapItem 7 : public GameEntity
8{ 8{
9public: 9public:
10 Point(QGraphicsItem *parent=0); 10 Point(QGraphicsItem *parent=0);
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp
index fc638f7..f0a5de3 100644
--- a/pacman-c++/sceneholder.cpp
+++ b/pacman-c++/sceneholder.cpp
@@ -1,6 +1,6 @@
1#include "sceneholder.h" 1#include "sceneholder.h"
2#include "constants.h" 2#include "constants.h"
3#include "pixmapitem.h" 3#include "gameentity.h"
4#include "block.h" 4#include "block.h"
5#include "actor.h" 5#include "actor.h"
6#include "bonuspoint.h" 6#include "bonuspoint.h"
@@ -20,6 +20,18 @@ SceneHolder::SceneHolder(QObject *parent)
20 20
21void SceneHolder::updateMap(const Transmission::map_t& map) 21void SceneHolder::updateMap(const Transmission::map_t& map)
22{ 22{
23 /* remove items that got marked for removal from scene */
24 QMutableListIterator<GameEntity *> i(m_oldItems);
25 while(i.hasNext())
26 {
27 i.next();
28 GameEntity *item = i.value();
29 removeItem(item);
30 i.remove();
31 delete item;
32 }
33
34 /* process update */
23 for (unsigned int x = 0; x < Constants::map_size.width; ++x) 35 for (unsigned int x = 0; x < Constants::map_size.width; ++x)
24 { 36 {
25 for (unsigned int y = 0; y < Constants::map_size.height; ++y) 37 for (unsigned int y = 0; y < Constants::map_size.height; ++y)
@@ -29,17 +41,16 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
29 continue; 41 continue;
30 42
31 Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); 43 Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask);
32 PixmapItem* item = NULL; 44 GameEntity* item = NULL;
33 45
34 if (cur & Transmission::empty) 46 if (cur & Transmission::empty)
35 { 47 {
36 PixmapItem *oldItem = visualMap[x][y]; 48 GameEntity *oldItem = visualMap[x][y];
37 /* special handling for purging field 49 /* special handling for purging field
38 * remove elements (in case it's not an actor) 50 * remove elements (in case it's not an actor)
39 */ 51 */
40 if (oldItem != NULL && dynamic_cast<Actor *>(oldItem) == NULL) 52 if (oldItem != NULL && dynamic_cast<Actor *>(oldItem) == NULL)
41 { 53 {
42 removeItem(oldItem);
43 visualMap[x][y] = NULL; 54 visualMap[x][y] = NULL;
44 Actor *actor = NULL; 55 Actor *actor = NULL;
45 foreach (Actor *tmp, m_actors) 56 foreach (Actor *tmp, m_actors)
@@ -51,10 +62,13 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
51 } 62 }
52 } 63 }
53 64
54 /* no actor removed that item */ 65 /* an item must be removed by an actor */
55 if (actor == NULL) 66 if (actor == NULL)
56 Q_ASSERT(false); 67 Q_ASSERT(false);
57 oldItem->onDie(actor); 68 oldItem->onDie(actor);
69
70 /* register item for removal in next update */
71 m_oldItems.append(oldItem);
58 } 72 }
59 } 73 }
60 74
@@ -122,7 +136,7 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
122 { 136 {
123 addItem(item); 137 addItem(item);
124 item->setPos(mapPositionToCoord(x, y)); 138 item->setPos(mapPositionToCoord(x, y));
125 PixmapItem *oldItem = visualMap[x][y]; 139 GameEntity *oldItem = visualMap[x][y];
126 visualMap[x][y] = item; 140 visualMap[x][y] = item;
127 if (oldItem != NULL) 141 if (oldItem != NULL)
128 { 142 {
diff --git a/pacman-c++/sceneholder.h b/pacman-c++/sceneholder.h
index 61cff3e..5183f65 100644
--- a/pacman-c++/sceneholder.h
+++ b/pacman-c++/sceneholder.h
@@ -4,7 +4,7 @@
4#include "constants.h" 4#include "constants.h"
5#include <QtGui> 5#include <QtGui>
6 6
7class PixmapItem; 7class GameEntity;
8class Actor; 8class Actor;
9 9
10class SceneHolder 10class SceneHolder
@@ -32,11 +32,16 @@ protected:
32 QPoint CoordToMapPosition(QPoint point); 32 QPoint CoordToMapPosition(QPoint point);
33 33
34 /* map of all pixmap instances */ 34 /* map of all pixmap instances */
35 QVector< QVector<PixmapItem *> > visualMap; 35 QVector< QVector<GameEntity *> > visualMap;
36 36
37 /* map of actors in order to keep track of those instances */ 37 /* map of actors in order to keep track of those instances */
38 QMap<Color::Color, Actor*> m_actors; 38 QMap<Color::Color, Actor*> m_actors;
39 39
40 /* items that got removed/has been eaten
41 * must be remove one tick later
42 */
43 QList<GameEntity *> m_oldItems;
44
40 /* my local color */ 45 /* my local color */
41 Color::Color m_color; 46 Color::Color m_color;
42 47
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp
index b0ac6f8..dd15934 100644
--- a/pacman-c++/server.cpp
+++ b/pacman-c++/server.cpp
@@ -83,21 +83,11 @@ invalid_direction:
83 83
84 // <t3h g4m3 10gic> 84 // <t3h g4m3 10gic>
85 // TODO: support actors eating each other 85 // TODO: support actors eating each other
86 // old item 86 /* check if there's an item at new location of actor */
87 PixmapItem *oldItem = visualMap[mapPosition.x()][mapPosition.y()]; 87 GameEntity *item = visualMap[newMapPosition.x()][newMapPosition.y()];
88 if (oldItem != NULL)
89 {
90 /* set item to explicit empty
91 * and add actor that removed/has eaten that item
92 */
93 if (oldItem->eaten())
94 map[mapPosition.x()][mapPosition.y()] = Transmission::empty | actor->color();
95 }
96
97 // new item
98 PixmapItem *item = visualMap[newMapPosition.x()][newMapPosition.y()];
99 if (item != NULL && oldItem != item) 88 if (item != NULL && oldItem != item)
100 { 89 {
90 qDebug() << "item at new actor location found";
101 if (!item->checkEnter(actor)) 91 if (!item->checkEnter(actor))
102 { 92 {
103 /* movement invalid. e.g. move against wall */ 93 /* movement invalid. e.g. move against wall */
@@ -105,11 +95,11 @@ invalid_direction:
105 } 95 }
106 else 96 else
107 { 97 {
108 // apply actions of entering this field 98 /* apply actions of entering this field */
109 bool survive = item->enter(actor); 99 bool survive = item->enter(actor);
110 if (!survive) 100 if (!survive)
111 { 101 {
112 //map[newMapPosition.x()][newMapPosition.y()] = Transmission::empty; 102 map[newMapPosition.x()][newMapPosition.y()] = Transmission::empty | actor->color();
113 } 103 }
114 } 104 }
115 } 105 }
@@ -134,6 +124,9 @@ invalid_direction:
134 map[newMapPosition.x()][newMapPosition.y()] |= Transmission::pacman | 124 map[newMapPosition.x()][newMapPosition.y()] |= Transmission::pacman |
135 i.key() | Util::actorMovementToTransmission(i.value()); 125 i.key() | Util::actorMovementToTransmission(i.value());
136 126
127 /* DEBUG: uncomments to disable auto-movement */
128 //m_actorMovements[i.key()] = Actor::None;
129
137 if (i.value() == Actor::None) 130 if (i.value() == Actor::None)
138 { 131 {
139 /* set actor to non-moving */ 132 /* set actor to non-moving */