diff options
| author | manuel <manuel@mausz.at> | 2011-05-02 15:50:23 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-05-02 15:50:23 +0200 |
| commit | ce20694e0db010b5d65bdd2ee81a410efbf99e3d (patch) | |
| tree | 6063fb3b023d156374936cc6d405abf3e57532cd /pacman-c++/sceneholder.cpp | |
| parent | 41a31420cf091aeb4e986503387855d41e550106 (diff) | |
| download | foop-ce20694e0db010b5d65bdd2ee81a410efbf99e3d.tar.gz foop-ce20694e0db010b5d65bdd2ee81a410efbf99e3d.tar.bz2 foop-ce20694e0db010b5d65bdd2ee81a410efbf99e3d.zip | |
w000h00
Diffstat (limited to 'pacman-c++/sceneholder.cpp')
| -rw-r--r-- | pacman-c++/sceneholder.cpp | 100 |
1 files changed, 63 insertions, 37 deletions
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index 1ecf31b..f6b8145 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp | |||
| @@ -25,7 +25,7 @@ void SceneHolder::reset() | |||
| 25 | /* remove actors from scene so they don't get deleted during clear */ | 25 | /* remove actors from scene so they don't get deleted during clear */ |
| 26 | foreach(Actor *actor, m_actors) | 26 | foreach(Actor *actor, m_actors) |
| 27 | { | 27 | { |
| 28 | actor->resetAnimation(); | 28 | actor->reset(); |
| 29 | removeItem(actor); | 29 | removeItem(actor); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| @@ -88,8 +88,20 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x | |||
| 88 | if (cur == Transmission::none) | 88 | if (cur == Transmission::none) |
| 89 | return; | 89 | return; |
| 90 | 90 | ||
| 91 | /* we may have multiple colors in one position (e.g during eating another pacman) */ | ||
| 91 | Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); | 92 | Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); |
| 92 | GameEntity* item = NULL; | 93 | QList<Color::Color> colors; |
| 94 | if (color == Color::none) | ||
| 95 | colors.append(Color::none); | ||
| 96 | foreach(Color::Color col, m_eatingorder.toSet()) | ||
| 97 | { | ||
| 98 | if (color & col) | ||
| 99 | colors.append(col); | ||
| 100 | } | ||
| 101 | Q_ASSERT(colors.count() > 0); | ||
| 102 | |||
| 103 | /* for now complain if there are more colors or it's a Transmission::death packet */ | ||
| 104 | Q_ASSERT(colors.count() == 1 || cur & Transmission::death); | ||
| 93 | 105 | ||
| 94 | if (cur & Transmission::empty) | 106 | if (cur & Transmission::empty) |
| 95 | { | 107 | { |
| @@ -102,13 +114,13 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x | |||
| 102 | m_oldItems.append(oldItem); | 114 | m_oldItems.append(oldItem); |
| 103 | 115 | ||
| 104 | /* an item must be removed by an actor */ | 116 | /* an item must be removed by an actor */ |
| 105 | Actor *actor = m_actors[color]; | 117 | Actor *actor = m_actors[colors.at(0)]; |
| 106 | if (actor == NULL) | 118 | Q_ASSERT(actor != NULL); |
| 107 | Q_ASSERT(false); | ||
| 108 | oldItem->onDie(actor); | 119 | oldItem->onDie(actor); |
| 109 | } | 120 | } |
| 110 | } | 121 | } |
| 111 | 122 | ||
| 123 | GameEntity *item = NULL; | ||
| 112 | if (cur == Transmission::none) | 124 | if (cur == Transmission::none) |
| 113 | { | 125 | { |
| 114 | /* no update */ | 126 | /* no update */ |
| @@ -137,7 +149,7 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x | |||
| 137 | /* check down side */ | 149 | /* check down side */ |
| 138 | if (y < Constants::map_size.height && map[x][y + 1] & Transmission::block) | 150 | if (y < Constants::map_size.height && map[x][y + 1] & Transmission::block) |
| 139 | neighbours |= Block::Down; | 151 | neighbours |= Block::Down; |
| 140 | item = new Block(color, neighbours); | 152 | item = new Block(colors.at(0), neighbours); |
| 141 | } | 153 | } |
| 142 | 154 | ||
| 143 | if (cur & Transmission::bonuspoint) | 155 | if (cur & Transmission::bonuspoint) |
| @@ -152,41 +164,55 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x | |||
| 152 | 164 | ||
| 153 | if (cur & Transmission::pacman) | 165 | if (cur & Transmission::pacman) |
| 154 | { | 166 | { |
| 155 | /* WARNING: do NOT add actor to visualMap as visualMap-items may | 167 | foreach(color, colors) |
| 156 | * get deleted during update and actors are referenced in_mactors too | ||
| 157 | * if you REALLY need that you need to changed updateMap so that all actors | ||
| 158 | * will be moved before any new items get allocated (totally untested) | ||
| 159 | */ | ||
| 160 | Actor *actor = m_actors.value(color, NULL); | ||
| 161 | if (actor == NULL) | ||
| 162 | { | ||
| 163 | actor = new Actor(color, (color == m_color)); | ||
| 164 | m_actors[color] = actor; | ||
| 165 | addItem(actor); | ||
| 166 | actor->setPos(mapPositionToCoord(x, y)); | ||
| 167 | } | ||
| 168 | else | ||
| 169 | { | 168 | { |
| 170 | Actor::Movement direction = Util::transmissionMovementToActor( | 169 | /* WARNING: do NOT add actor to visualMap as visualMap-items may |
| 171 | cur & Transmission::direction_mask); | 170 | * get deleted during update and actors are referenced in_mactors too |
| 172 | /* direction Actor::None is used on round change (i.e. new actor positions) | 171 | * if you REALLY need that you need to changed updateMap so that all actors |
| 173 | * it is animation-safe to use it for this direction only | 172 | * will be moved before any new items get allocated (totally untested) |
| 174 | */ | 173 | */ |
| 175 | if (direction == Actor::None) | 174 | Actor *actor = m_actors.value(color, NULL); |
| 175 | if (actor == NULL) | ||
| 176 | { | ||
| 177 | actor = new Actor(color, (color == m_color)); | ||
| 178 | m_actors[color] = actor; | ||
| 179 | addItem(actor); | ||
| 176 | actor->setPos(mapPositionToCoord(x, y)); | 180 | actor->setPos(mapPositionToCoord(x, y)); |
| 177 | actor->move(direction); | 181 | actor->hadReset(); |
| 178 | /* that's kind a hack but working right now | 182 | } |
| 179 | * I think that will fall on our's hat sooner or later | 183 | else |
| 180 | */ | 184 | { |
| 181 | if (!(cur & Transmission::empty)) | 185 | /* check for death */ |
| 182 | actor->stopEating(); | 186 | if (cur & Transmission::death) |
| 183 | qDebug() << "[SceneUpdate] actor moves: color=" << color | 187 | { |
| 184 | << "direction=" << direction << "newpos=" << QPoint(x, y); | 188 | foreach(Color::Color col, colors) |
| 189 | { | ||
| 190 | if (color == col) | ||
| 191 | continue; | ||
| 192 | if (m_actors[col]->canEat(actor, m_eatingorder)) | ||
| 193 | { | ||
| 194 | m_death[col] = actor; | ||
| 195 | break; | ||
| 196 | } | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | /* move actor */ | ||
| 201 | if (actor->hadReset()) | ||
| 202 | actor->setPos(mapPositionToCoord(x, y)); | ||
| 203 | else | ||
| 204 | actor->move(mapPositionToCoord(x, y)); | ||
| 205 | |||
| 206 | /* that's kind a hack but working right now */ | ||
| 207 | if (!(cur & Transmission::empty)) | ||
| 208 | actor->stopEating(); | ||
| 209 | qDebug() << "[SceneUpdate] actor moves: color=" << color | ||
| 210 | << "newpos=" << QPoint(x, y); | ||
| 211 | } | ||
| 212 | |||
| 213 | if ((cur & Transmission::death) && visualMap[x][y] != NULL) | ||
| 214 | m_death[color] = visualMap[x][y]; | ||
| 185 | } | 215 | } |
| 186 | |||
| 187 | |||
| 188 | if (cur & Transmission::death) | ||
| 189 | m_death[color] = visualMap[x][y]; | ||
| 190 | } | 216 | } |
| 191 | 217 | ||
| 192 | if (cur & Transmission::empty) | 218 | if (cur & Transmission::empty) |
