summaryrefslogtreecommitdiffstats
path: root/pacman-c++/sceneholder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pacman-c++/sceneholder.cpp')
-rw-r--r--pacman-c++/sceneholder.cpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp
index 1610b7e..56e0fff 100644
--- a/pacman-c++/sceneholder.cpp
+++ b/pacman-c++/sceneholder.cpp
@@ -18,6 +18,13 @@ SceneHolder::SceneHolder(QObject *parent)
18 visualMap[i].resize(Constants::map_size.height); 18 visualMap[i].resize(Constants::map_size.height);
19} 19}
20 20
21void SceneHolder::reset()
22{
23 /* reset actor directions */
24 foreach(Actor *actor, m_actors)
25 actor->resetDirection();
26}
27
21void SceneHolder::updateMap(const Transmission::map_t& map) 28void SceneHolder::updateMap(const Transmission::map_t& map)
22{ 29{
23 /* remove items that got marked for removal from scene */ 30 /* remove items that got marked for removal from scene */
@@ -42,6 +49,9 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
42 updateMap(map, x, y); 49 updateMap(map, x, y);
43 } 50 }
44 } 51 }
52
53 if (m_pointsLeft == 0)
54 emit allPointsRemoved();
45} 55}
46 56
47void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x, unsigned int y) 57void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x, unsigned int y)
@@ -83,30 +93,30 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x
83 93
84 if (cur == Transmission::none) 94 if (cur == Transmission::none)
85 { 95 {
86 // no update 96 /* no update */
87 } 97 }
88 else 98 else
89 { 99 {
90 if (cur & Transmission::block) 100 if (cur & Transmission::block)
91 { 101 {
92 unsigned int neighbours = Block::None; 102 unsigned int neighbours = Block::None;
93 // check for old block first 103 /* check for old block first */
94 if (visualMap[x][y] != NULL) 104 if (visualMap[x][y] != NULL)
95 { 105 {
96 Block *oldItem = qgraphicsitem_cast<Block *>(visualMap[x][y]); 106 Block *oldItem = qgraphicsitem_cast<Block *>(visualMap[x][y]);
97 if (oldItem != NULL) 107 if (oldItem != NULL)
98 neighbours = oldItem->neighbours(); 108 neighbours = oldItem->neighbours();
99 } 109 }
100 // check left side 110 /* check left side */
101 if (x > 0 && map[x - 1][y] & Transmission::block) 111 if (x > 0 && map[x - 1][y] & Transmission::block)
102 neighbours |= Block::Left; 112 neighbours |= Block::Left;
103 // check right side 113 /* check right side */
104 if (x < Constants::map_size.width && map[x + 1][y] & Transmission::block) 114 if (x < Constants::map_size.width && map[x + 1][y] & Transmission::block)
105 neighbours |= Block::Right; 115 neighbours |= Block::Right;
106 // check upside 116 /* check upside */
107 if (y > 0 && map[x][y - 1] & Transmission::block) 117 if (y > 0 && map[x][y - 1] & Transmission::block)
108 neighbours |= Block::Up; 118 neighbours |= Block::Up;
109 // check down side 119 /* check down side */
110 if (y < Constants::map_size.height && map[x][y + 1] & Transmission::block) 120 if (y < Constants::map_size.height && map[x][y + 1] & Transmission::block)
111 neighbours |= Block::Down; 121 neighbours |= Block::Down;
112 item = new Block(color, neighbours); 122 item = new Block(color, neighbours);
@@ -124,6 +134,11 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x
124 134
125 if (cur & Transmission::pacman) 135 if (cur & Transmission::pacman)
126 { 136 {
137 /* WARNING: do NOT add actor to visualMap as visualMap-items may
138 * get deleted during update and actors are referenced in_mactors too
139 * if you REALLY need that you need to changed updateMap so that all actors
140 * will be moved before any new items get allocated (totally untested)
141 */
127 Actor *actor = m_actors.value(color, NULL); 142 Actor *actor = m_actors.value(color, NULL);
128 if (actor == NULL) 143 if (actor == NULL)
129 { 144 {
@@ -136,11 +151,11 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x
136 { 151 {
137 Actor::Movement direction = Util::transmissionMovementToActor( 152 Actor::Movement direction = Util::transmissionMovementToActor(
138 cur & Transmission::direction_mask); 153 cur & Transmission::direction_mask);
139 /* WARNING: do NOT add actor to visualMap as visualMap-items may 154 /* direction Actor::None is used on round change (i.e. new actor positions)
140 * get deleted during update and actors are referenced in_mactors too 155 * it is animation-safe to use it for this direction only
141 * if you REALLY need that you need to changed updateMap so that all actors
142 * will be moved before any new items get allocated (totally untested)
143 */ 156 */
157 if (direction == Actor::None)
158 actor->setPos(mapPositionToCoord(x, y));
144 actor->move(direction); 159 actor->move(direction);
145 /* that's kind a hack but working right now 160 /* that's kind a hack but working right now
146 * I think that will fall on our's hat sooner or later 161 * I think that will fall on our's hat sooner or later
@@ -194,8 +209,6 @@ unsigned int SceneHolder::pointsLeft()
194void SceneHolder::decrementPoints() 209void SceneHolder::decrementPoints()
195{ 210{
196 --m_pointsLeft; 211 --m_pointsLeft;
197 if (m_pointsLeft == 0)
198 emit allPointsRemoved();
199} 212}
200 213
201void SceneHolder::setEatingOrder(QList<Color::Color> &order) 214void SceneHolder::setEatingOrder(QList<Color::Color> &order)