diff options
Diffstat (limited to 'pacman-c++/sceneholder.cpp')
| -rw-r--r-- | pacman-c++/sceneholder.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index b788a49..fc638f7 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp | |||
| @@ -33,25 +33,28 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 33 | 33 | ||
| 34 | if (cur & Transmission::empty) | 34 | if (cur & Transmission::empty) |
| 35 | { | 35 | { |
| 36 | /* special handling for purging field */ | ||
| 37 | PixmapItem *oldItem = visualMap[x][y]; | 36 | PixmapItem *oldItem = visualMap[x][y]; |
| 38 | /* remove elements (in case it's not an actor) */ | 37 | /* special handling for purging field |
| 39 | if (oldItem != NULL && dynamic_cast<Actor *>(item) == NULL) | 38 | * remove elements (in case it's not an actor) |
| 39 | */ | ||
| 40 | if (oldItem != NULL && dynamic_cast<Actor *>(oldItem) == NULL) | ||
| 40 | { | 41 | { |
| 41 | removeItem(oldItem); | 42 | removeItem(oldItem); |
| 42 | visualMap[x][y] = NULL; | 43 | visualMap[x][y] = NULL; |
| 43 | Actor *actor = NULL; | 44 | Actor *actor = NULL; |
| 44 | foreach (Actor *i, m_actors) | 45 | foreach (Actor *tmp, m_actors) |
| 45 | { | 46 | { |
| 46 | if (CoordToMapPosition(i->pos().toPoint()) == QPoint(x, y)) | 47 | if (cur & tmp->color()) |
| 47 | { | 48 | { |
| 48 | actor = i; | 49 | actor = tmp; |
| 49 | break; | 50 | break; |
| 50 | } | 51 | } |
| 51 | } | 52 | } |
| 53 | |||
| 54 | /* no actor removed that item */ | ||
| 55 | if (actor == NULL) | ||
| 56 | Q_ASSERT(false); | ||
| 52 | oldItem->onDie(actor); | 57 | oldItem->onDie(actor); |
| 53 | delete oldItem; | ||
| 54 | //qDebug() << "deleting " << x << y; | ||
| 55 | } | 58 | } |
| 56 | } | 59 | } |
| 57 | 60 | ||
| @@ -112,11 +115,14 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 112 | Q_ASSERT(false); | 115 | Q_ASSERT(false); |
| 113 | } | 116 | } |
| 114 | 117 | ||
| 118 | /* add new created item to scene | ||
| 119 | * remove old item on that location if there's one | ||
| 120 | */ | ||
| 115 | if (item != NULL) | 121 | if (item != NULL) |
| 116 | { | 122 | { |
| 117 | addItem(item); | 123 | addItem(item); |
| 118 | item->setPos(mapPositionToCoord(x, y)); | 124 | item->setPos(mapPositionToCoord(x, y)); |
| 119 | PixmapItem* oldItem = visualMap[x][y]; | 125 | PixmapItem *oldItem = visualMap[x][y]; |
| 120 | visualMap[x][y] = item; | 126 | visualMap[x][y] = item; |
| 121 | if (oldItem != NULL) | 127 | if (oldItem != NULL) |
| 122 | { | 128 | { |
| @@ -126,7 +132,6 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 126 | } | 132 | } |
| 127 | } | 133 | } |
| 128 | } | 134 | } |
| 129 | |||
| 130 | } | 135 | } |
| 131 | 136 | ||
| 132 | void SceneHolder::setColor(Color::Color color) | 137 | void SceneHolder::setColor(Color::Color color) |
| @@ -147,7 +152,6 @@ unsigned int SceneHolder::pointsLeft() | |||
| 147 | void SceneHolder::decrementPoints() | 152 | void SceneHolder::decrementPoints() |
| 148 | { | 153 | { |
| 149 | --m_pointsLeft; | 154 | --m_pointsLeft; |
| 150 | qDebug() << "points left=" << m_pointsLeft; | ||
| 151 | } | 155 | } |
| 152 | 156 | ||
| 153 | QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) | 157 | QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) |
