From bbd2a69a962d15f74a4afcb7b66462eac9fa5008 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 20 Apr 2011 02:19:08 +0200 Subject: game rounds finally implemented: - game rounds will be detected during the round AND - a new map will be send in the NEXT tick to the clients --- pacman-c++/sceneholder.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'pacman-c++/sceneholder.cpp') 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) visualMap[i].resize(Constants::map_size.height); } +void SceneHolder::reset() +{ + /* reset actor directions */ + foreach(Actor *actor, m_actors) + actor->resetDirection(); +} + void SceneHolder::updateMap(const Transmission::map_t& map) { /* remove items that got marked for removal from scene */ @@ -42,6 +49,9 @@ void SceneHolder::updateMap(const Transmission::map_t& map) updateMap(map, x, y); } } + + if (m_pointsLeft == 0) + emit allPointsRemoved(); } void 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 if (cur == Transmission::none) { - // no update + /* no update */ } else { if (cur & Transmission::block) { unsigned int neighbours = Block::None; - // check for old block first + /* check for old block first */ if (visualMap[x][y] != NULL) { Block *oldItem = qgraphicsitem_cast(visualMap[x][y]); if (oldItem != NULL) neighbours = oldItem->neighbours(); } - // check left side + /* check left side */ if (x > 0 && map[x - 1][y] & Transmission::block) neighbours |= Block::Left; - // check right side + /* check right side */ if (x < Constants::map_size.width && map[x + 1][y] & Transmission::block) neighbours |= Block::Right; - // check upside + /* check upside */ if (y > 0 && map[x][y - 1] & Transmission::block) neighbours |= Block::Up; - // check down side + /* check down side */ if (y < Constants::map_size.height && map[x][y + 1] & Transmission::block) neighbours |= Block::Down; item = new Block(color, neighbours); @@ -124,6 +134,11 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x if (cur & Transmission::pacman) { + /* WARNING: do NOT add actor to visualMap as visualMap-items may + * get deleted during update and actors are referenced in_mactors too + * if you REALLY need that you need to changed updateMap so that all actors + * will be moved before any new items get allocated (totally untested) + */ Actor *actor = m_actors.value(color, NULL); if (actor == NULL) { @@ -136,11 +151,11 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x { Actor::Movement direction = Util::transmissionMovementToActor( cur & Transmission::direction_mask); - /* WARNING: do NOT add actor to visualMap as visualMap-items may - * get deleted during update and actors are referenced in_mactors too - * if you REALLY need that you need to changed updateMap so that all actors - * will be moved before any new items get allocated (totally untested) + /* direction Actor::None is used on round change (i.e. new actor positions) + * it is animation-safe to use it for this direction only */ + if (direction == Actor::None) + actor->setPos(mapPositionToCoord(x, y)); actor->move(direction); /* that's kind a hack but working right now * I think that will fall on our's hat sooner or later @@ -194,8 +209,6 @@ unsigned int SceneHolder::pointsLeft() void SceneHolder::decrementPoints() { --m_pointsLeft; - if (m_pointsLeft == 0) - emit allPointsRemoved(); } void SceneHolder::setEatingOrder(QList &order) -- cgit v1.2.3