summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pacman-c++/actor.cpp2
-rw-r--r--pacman-c++/block.h10
-rw-r--r--pacman-c++/client.cpp2
-rw-r--r--pacman-c++/constants.h2
-rw-r--r--pacman-c++/gameentity.cpp1
-rw-r--r--pacman-c++/gameentity.h47
-rw-r--r--pacman-c++/sceneholder.cpp6
-rw-r--r--pacman-c++/server.cpp23
8 files changed, 61 insertions, 32 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp
index e34d338..a97232f 100644
--- a/pacman-c++/actor.cpp
+++ b/pacman-c++/actor.cpp
@@ -89,7 +89,7 @@ QSequentialAnimationGroup *Actor::setupEatingAnimation(Actor::Movement direction
89 fadeout->setEndValue(false); 89 fadeout->setEndValue(false);
90 90
91 QPropertyAnimation *move = new QPropertyAnimation(img, "pos", m_moving); 91 QPropertyAnimation *move = new QPropertyAnimation(img, "pos", m_moving);
92 move->setDuration(Constants::tick - 20); //TODO 92 move->setDuration(Constants::tick - 50); //TODO
93 move->setEndValue(QPoint(0, 0)); 93 move->setEndValue(QPoint(0, 0));
94 } 94 }
95 95
diff --git a/pacman-c++/block.h b/pacman-c++/block.h
index b5a4bf3..9e49a7d 100644
--- a/pacman-c++/block.h
+++ b/pacman-c++/block.h
@@ -9,7 +9,8 @@ class Block
9 : public PixmapItem 9 : public PixmapItem
10{ 10{
11public: 11public:
12 enum Neighbour { 12 enum Neighbour
13 {
13 None = 0, 14 None = 0,
14 Left = (1 << 0), 15 Left = (1 << 0),
15 Right = (1 << 1), 16 Right = (1 << 1),
@@ -23,8 +24,11 @@ public:
23 {}; 24 {};
24 25
25 void setNeighbours(unsigned int neighbours); 26 void setNeighbours(unsigned int neighbours);
26 27 virtual bool checkEnter(Actor *)
27 virtual bool checkEnter(Actor *actor) { Q_UNUSED(actor); return false; } // TODO: colored blocks 28 {
29 /* TODO: colored blocks */
30 return false;
31 }
28 32
29private: 33private:
30 // map for saving QPixmaps for reuse 34 // map for saving QPixmaps for reuse
diff --git a/pacman-c++/client.cpp b/pacman-c++/client.cpp
index d885e49..3d45ebd 100644
--- a/pacman-c++/client.cpp
+++ b/pacman-c++/client.cpp
@@ -63,6 +63,8 @@ void Client::mutedChanged(bool muted) const
63 m_settings->setValue("muted", muted); 63 m_settings->setValue("muted", muted);
64} 64}
65 65
66bool Constants::server = false;
67
66int main(int argc, char ** argv) 68int main(int argc, char ** argv)
67{ 69{
68 GOOGLE_PROTOBUF_VERIFY_VERSION; 70 GOOGLE_PROTOBUF_VERIFY_VERSION;
diff --git a/pacman-c++/constants.h b/pacman-c++/constants.h
index 90963fe..15eba86 100644
--- a/pacman-c++/constants.h
+++ b/pacman-c++/constants.h
@@ -15,7 +15,7 @@ namespace Constants {
15 const unsigned int sprite_margin = 2; 15 const unsigned int sprite_margin = 2;
16 const unsigned int sprite_offset = 20; 16 const unsigned int sprite_offset = 20;
17 const unsigned int tick = 250; // ms 17 const unsigned int tick = 250; // ms
18 static bool server = false; 18 extern bool server;
19 19
20 namespace Networking 20 namespace Networking
21 { 21 {
diff --git a/pacman-c++/gameentity.cpp b/pacman-c++/gameentity.cpp
index e8743df..ec43d93 100644
--- a/pacman-c++/gameentity.cpp
+++ b/pacman-c++/gameentity.cpp
@@ -5,6 +5,5 @@
5GameEntity::GameEntity() 5GameEntity::GameEntity()
6 : m_eaten(false) 6 : m_eaten(false)
7{ 7{
8
9} 8}
10 9
diff --git a/pacman-c++/gameentity.h b/pacman-c++/gameentity.h
index 0c0ab9c..afa3aba 100644
--- a/pacman-c++/gameentity.h
+++ b/pacman-c++/gameentity.h
@@ -8,24 +8,39 @@ class Actor;
8/** 8/**
9 * Base class for entities that interact in the game 9 * Base class for entities that interact in the game
10 */ 10 */
11class GameEntity { 11class GameEntity
12{
12public: 13public:
13 GameEntity(); 14 GameEntity();
14 virtual ~GameEntity() {}; 15 virtual ~GameEntity()
15 16 {};
16 // returns whether the actor may enter this field 17
17 virtual bool checkEnter(Actor *actor) { Q_UNUSED(actor); return true; } // default to true 18 /* returns whether the actor may enter this field */
18 19 virtual bool checkEnter(Actor *)
19 // performs action when this actor acctually enters 20 {
20 // returns whether this entity survives the entering 21 return true;
21 virtual bool enter(Actor *actor) { Q_UNUSED(actor); return true; } // default to no action/survive 22 }
22 23
23 // check whether this entity is regarded as eaten 24 /* performs action when this actor acctually enters
24 // (and can be removed in the next tick) 25 * returns whether this entity survives the entering
25 virtual bool eaten() { return m_eaten; } 26 */
26 27 virtual bool enter(Actor *)
27 // called when an instance acctually dies for creating effects 28 {
28 virtual void onDie(Actor *actor) { Q_UNUSED(actor); }; 29 /* default to no action/survive */
30 return true;
31 }
32
33 /* check whether this entity is regarded as eaten
34 * (and can be removed in the next tick)
35 */
36 virtual bool eaten()
37 {
38 return m_eaten;
39 }
40
41 /* called when an instance acctually dies for creating effects */
42 virtual void onDie(Actor *)
43 {};
29 44
30 45
31protected: 46protected:
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp
index 26f74a7..0047e59 100644
--- a/pacman-c++/sceneholder.cpp
+++ b/pacman-c++/sceneholder.cpp
@@ -41,8 +41,10 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
41 m_scene->removeItem(oldItem); 41 m_scene->removeItem(oldItem);
42 visualMap[x][y] = NULL; 42 visualMap[x][y] = NULL;
43 Actor *actor = NULL; 43 Actor *actor = NULL;
44 foreach (Actor *i, m_actors) { 44 foreach (Actor *i, m_actors)
45 if (CoordToMapPosition(i->pos().x(), i->pos().y()) == QPoint(x, y)) { 45 {
46 if (CoordToMapPosition(i->pos().toPoint()) == QPoint(x, y))
47 {
46 actor = i; 48 actor = i;
47 break; 49 break;
48 } 50 }
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp
index 43aa6ff..965517e 100644
--- a/pacman-c++/server.cpp
+++ b/pacman-c++/server.cpp
@@ -81,19 +81,26 @@ Transmission::map_t Server::calculateUpdates()
81 // TODO: support actors eating each other 81 // TODO: support actors eating each other
82 // old item 82 // old item
83 PixmapItem *oldItem = visualMap[mapPosition.x()][mapPosition.y()]; 83 PixmapItem *oldItem = visualMap[mapPosition.x()][mapPosition.y()];
84 if (oldItem != NULL) { 84 if (oldItem != NULL)
85 if (oldItem->eaten()) { 85 {
86 if (oldItem->eaten())
86 map[mapPosition.x()][mapPosition.y()] = Transmission::empty; 87 map[mapPosition.x()][mapPosition.y()] = Transmission::empty;
87 }
88 } 88 }
89 // new item 89 // new item
90 PixmapItem *item = visualMap[newMapPosition.x()][newMapPosition.y()]; 90 PixmapItem *item = visualMap[newMapPosition.x()][newMapPosition.y()];
91 if (item != NULL && oldItem != item) { 91 if (item != NULL && oldItem != item)
92 if (! item->checkEnter(actor)) { // movement invalid 92 {
93 if (! item->checkEnter(actor))
94 {
95 // movement invalid
93 newMapPosition = mapPosition; 96 newMapPosition = mapPosition;
94 } else { // apply actions of entering this field 97 }
98 else
99 {
100 // apply actions of entering this field
95 bool survive = item->enter(actor); 101 bool survive = item->enter(actor);
96 if (!survive) { 102 if (!survive)
103 {
97 //map[newMapPosition.x()][newMapPosition.y()] = Transmission::empty; 104 //map[newMapPosition.x()][newMapPosition.y()] = Transmission::empty;
98 } 105 }
99 } 106 }
@@ -197,6 +204,7 @@ void Server::keyPressUpdate()
197 } 204 }
198} 205}
199 206
207bool Constants::server = true;
200 208
201int main(int argc, char ** argv) 209int main(int argc, char ** argv)
202{ 210{
@@ -208,7 +216,6 @@ int main(int argc, char ** argv)
208 216
209 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); 217 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
210 218
211 Constants::server = true;
212 Server Server; 219 Server Server;
213 return app.exec(); 220 return app.exec();
214} 221}