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.cpp120
1 files changed, 65 insertions, 55 deletions
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp
index 11e0772..38b49e5 100644
--- a/pacman-c++/sceneholder.cpp
+++ b/pacman-c++/sceneholder.cpp
@@ -86,68 +86,77 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x
86 { 86 {
87 // no update 87 // no update
88 } 88 }
89 else if (cur & Transmission::block) 89 else
90 {
91 unsigned int neighbours = Block::None;
92 // check left side
93 if (x > 0 && map[x - 1][y] & Transmission::block)
94 neighbours |= Block::Left;
95 // check right side
96 if (x < Constants::map_size.width && map[x + 1][y] & Transmission::block)
97 neighbours |= Block::Right;
98 // check upside
99 if (y > 0 && map[x][y - 1] & Transmission::block)
100 neighbours |= Block::Up;
101 // check down side
102 if (y < Constants::map_size.height && map[x][y + 1] & Transmission::block)
103 neighbours |= Block::Down;
104 item = new Block(color, neighbours);
105 }
106 else if (cur & Transmission::bonuspoint)
107 item = new BonusPoint();
108 else if (cur & Transmission::point)
109 {
110 item = new Point();
111 connect(item, SIGNAL(destroyed()), this, SLOT(decrementPoints()));
112 ++m_pointsLeft;
113 }
114 else if (cur & Transmission::pacman)
115 { 90 {
116 Actor *actor = m_actors.value(color, NULL); 91 if (cur & Transmission::block)
117 if (actor == NULL) 92 {
93 unsigned int neighbours = Block::None;
94 // check for old block first
95 if (visualMap[x][y] != NULL)
96 {
97 Block *oldItem = dynamic_cast<Block *>(visualMap[x][y]);
98 if (oldItem != NULL)
99 neighbours = oldItem->neighbours();
100 }
101 // check left side
102 if (x > 0 && map[x - 1][y] & Transmission::block)
103 neighbours |= Block::Left;
104 // check right side
105 if (x < Constants::map_size.width && map[x + 1][y] & Transmission::block)
106 neighbours |= Block::Right;
107 // check upside
108 if (y > 0 && map[x][y - 1] & Transmission::block)
109 neighbours |= Block::Up;
110 // check down side
111 if (y < Constants::map_size.height && map[x][y + 1] & Transmission::block)
112 neighbours |= Block::Down;
113 item = new Block(color, neighbours);
114 }
115
116 if (cur & Transmission::bonuspoint)
117 item = new BonusPoint();
118
119 if (cur & Transmission::point)
118 { 120 {
119 actor = new Actor(color, (color == m_color)); 121 item = new Point();
120 m_actors[color] = actor; 122 connect(item, SIGNAL(destroyed()), this, SLOT(decrementPoints()));
121 addItem(actor); 123 ++m_pointsLeft;
122 actor->setPos(mapPositionToCoord(x, y));
123 } 124 }
124 else 125
126 if (cur & Transmission::pacman)
125 { 127 {
126 Actor::Movement direction = Util::transmissionMovementToActor( 128 Actor *actor = m_actors.value(color, NULL);
127 cur & Transmission::direction_mask); 129 if (actor == NULL)
128 /* WARNING: do NOT add actor to visualMap as visualMap-items may 130 {
131 actor = new Actor(color, (color == m_color));
132 m_actors[color] = actor;
133 addItem(actor);
134 actor->setPos(mapPositionToCoord(x, y));
135 }
136 else
137 {
138 Actor::Movement direction = Util::transmissionMovementToActor(
139 cur & Transmission::direction_mask);
140 /* WARNING: do NOT add actor to visualMap as visualMap-items may
129 * get deleted during update and actors are referenced in_mactors too 141 * get deleted during update and actors are referenced in_mactors too
130 * if you REALLY need that you need to changed updateMap so that all actors 142 * if you REALLY need that you need to changed updateMap so that all actors
131 * will be moved before any new items get allocated (totally untested) 143 * will be moved before any new items get allocated (totally untested)
132 */ 144 */
133 actor->move(direction); 145 actor->move(direction);
134 /* that's kind a hack but working right now 146 /* that's kind a hack but working right now
135 * I think that will fall on our's hat sooner or later 147 * I think that will fall on our's hat sooner or later
136 */ 148 */
137 if (!(cur & Transmission::empty)) 149 if (!(cur & Transmission::empty))
138 actor->stopEating(); 150 actor->stopEating();
139 qDebug() << "[SceneUpdate] actor moves: color=" << color 151 qDebug() << "[SceneUpdate] actor moves: color=" << color
140 << "direction=" << direction << "newpos=" << QPoint(x, y); 152 << "direction=" << direction << "newpos=" << QPoint(x, y);
153 }
154 }
155
156 if (cur & Transmission::empty)
157 {
158 /* already handled */
141 } 159 }
142 }
143 else if (cur & Transmission::empty)
144 {
145 /* already handled */
146 }
147 else
148 {
149 qWarning() << "Unknown data. value=" << cur;
150 Q_ASSERT(false);
151 } 160 }
152 161
153 /* add new created item to scene 162 /* add new created item to scene
@@ -155,15 +164,16 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x
155 */ 164 */
156 if (item != NULL) 165 if (item != NULL)
157 { 166 {
158 addItem(item);
159 item->setPos(mapPositionToCoord(x, y));
160 GameEntity *oldItem = visualMap[x][y]; 167 GameEntity *oldItem = visualMap[x][y];
161 visualMap[x][y] = item;
162 if (oldItem != NULL) 168 if (oldItem != NULL)
163 { 169 {
164 removeItem(item); 170 removeItem(oldItem);
165 delete oldItem; 171 delete oldItem;
166 } 172 }
173
174 addItem(item);
175 item->setPos(mapPositionToCoord(x, y));
176 visualMap[x][y] = item;
167 } 177 }
168} 178}
169 179