summaryrefslogtreecommitdiffstats
path: root/pacman-c++/sceneholder.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-25 14:39:00 +0200
committermanuel <manuel@mausz.at>2011-04-25 14:39:00 +0200
commit41a31420cf091aeb4e986503387855d41e550106 (patch)
treeffbe0be5f9630a0bab2deb0b5df37c174bf40db1 /pacman-c++/sceneholder.cpp
parentbbd2a69a962d15f74a4afcb7b66462eac9fa5008 (diff)
downloadfoop-41a31420cf091aeb4e986503387855d41e550106.tar.gz
foop-41a31420cf091aeb4e986503387855d41e550106.tar.bz2
foop-41a31420cf091aeb4e986503387855d41e550106.zip
- add intro sound on every round
- add dieing sound - add dieing animation - add die on moving onto colorized block
Diffstat (limited to 'pacman-c++/sceneholder.cpp')
-rw-r--r--pacman-c++/sceneholder.cpp76
1 files changed, 44 insertions, 32 deletions
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp
index 56e0fff..1ecf31b 100644
--- a/pacman-c++/sceneholder.cpp
+++ b/pacman-c++/sceneholder.cpp
@@ -20,23 +20,51 @@ SceneHolder::SceneHolder(QObject *parent)
20 20
21void SceneHolder::reset() 21void SceneHolder::reset()
22{ 22{
23 /* reset actor directions */ 23 processDelayedItems();
24
25 /* remove actors from scene so they don't get deleted during clear */
24 foreach(Actor *actor, m_actors) 26 foreach(Actor *actor, m_actors)
25 actor->resetDirection(); 27 {
28 actor->resetAnimation();
29 removeItem(actor);
30 }
31
32 /* clear our stuff */
33 clear();
34 m_pointsLeft = 0;
35 for (int i = 0; i < visualMap.size(); ++i)
36 {
37 visualMap[i].clear();
38 visualMap[i].resize(Constants::map_size.height);
39 }
40
41 /* add actors again */
42 foreach(Actor *actor, m_actors)
43 addItem(actor);
26} 44}
27 45
28void SceneHolder::updateMap(const Transmission::map_t& map) 46void SceneHolder::processDelayedItems()
29{ 47{
30 /* remove items that got marked for removal from scene */ 48 /* remove items that got marked for removal from scene */
31 QMutableListIterator<GameEntity *> i(m_oldItems); 49 foreach(GameEntity *item, m_oldItems)
32 while(i.hasNext())
33 { 50 {
34 i.next();
35 GameEntity *item = i.value();
36 removeItem(item); 51 removeItem(item);
37 i.remove();
38 delete item; 52 delete item;
39 } 53 }
54 m_oldItems.clear();
55
56 /* process death */
57 foreach(const Color::Color color, m_death.keys())
58 {
59 Q_ASSERT(m_death[color] != NULL);
60 m_death[color]->onDie(m_actors[color]);
61 }
62 m_death.clear();
63}
64
65void SceneHolder::updateMap(const Transmission::map_t& map)
66{
67 processDelayedItems();
40 68
41 /* process update */ 69 /* process update */
42 for (unsigned int x = 0; x < Constants::map_size.width; ++x) 70 for (unsigned int x = 0; x < Constants::map_size.width; ++x)
@@ -66,28 +94,18 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x
66 if (cur & Transmission::empty) 94 if (cur & Transmission::empty)
67 { 95 {
68 GameEntity *oldItem = visualMap[x][y]; 96 GameEntity *oldItem = visualMap[x][y];
69 /* special handling for purging field 97 /* special handling for purging field */
70 */
71 if (oldItem != NULL) 98 if (oldItem != NULL)
72 { 99 {
100 /* remove item from visualmap and register item for removal in next update */
73 visualMap[x][y] = NULL; 101 visualMap[x][y] = NULL;
74 Actor *actor = NULL; 102 m_oldItems.append(oldItem);
75 foreach (Actor *tmp, m_actors)
76 {
77 if (cur & tmp->color())
78 {
79 actor = tmp;
80 break;
81 }
82 }
83 103
84 /* an item must be removed by an actor */ 104 /* an item must be removed by an actor */
105 Actor *actor = m_actors[color];
85 if (actor == NULL) 106 if (actor == NULL)
86 Q_ASSERT(false); 107 Q_ASSERT(false);
87 oldItem->onDie(actor); 108 oldItem->onDie(actor);
88
89 /* register item for removal in next update */
90 m_oldItems.append(oldItem);
91 } 109 }
92 } 110 }
93 111
@@ -165,6 +183,10 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x
165 qDebug() << "[SceneUpdate] actor moves: color=" << color 183 qDebug() << "[SceneUpdate] actor moves: color=" << color
166 << "direction=" << direction << "newpos=" << QPoint(x, y); 184 << "direction=" << direction << "newpos=" << QPoint(x, y);
167 } 185 }
186
187
188 if (cur & Transmission::death)
189 m_death[color] = visualMap[x][y];
168 } 190 }
169 191
170 if (cur & Transmission::empty) 192 if (cur & Transmission::empty)
@@ -221,16 +243,6 @@ QList<Color::Color> &SceneHolder::eatingOrder()
221 return m_eatingorder; 243 return m_eatingorder;
222} 244}
223 245
224void SceneHolder::removeActors()
225{
226 foreach(Actor *actor, m_actors)
227 {
228 removeItem(actor);
229 delete actor;
230 }
231 m_actors.clear();
232}
233
234QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) 246QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y)
235{ 247{
236 return QPoint(x * Constants::field_size.width, y * Constants::field_size.height); 248 return QPoint(x * Constants::field_size.width, y * Constants::field_size.height);