diff options
| author | manuel <manuel@mausz.at> | 2011-04-11 14:15:59 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-11 14:15:59 +0200 |
| commit | c68e77cac9558316ac16d58c0f6b888599ab021a (patch) | |
| tree | 556b4c36fb325a117dd2ff27c472689a82c1a156 /pacman-c++/server.cpp | |
| parent | 3c2e420d3418f326e091c67673f9eec610e45fc2 (diff) | |
| download | foop-c68e77cac9558316ac16d58c0f6b888599ab021a.tar.gz foop-c68e77cac9558316ac16d58c0f6b888599ab021a.tar.bz2 foop-c68e77cac9558316ac16d58c0f6b888599ab021a.zip | |
- make moving animation a bit smoother (on my computer at least)
- make animation stop after getting blocked
Diffstat (limited to 'pacman-c++/server.cpp')
| -rw-r--r-- | pacman-c++/server.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 965517e..8b07882 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -35,10 +35,11 @@ Transmission::map_t Server::calculateUpdates() | |||
| 35 | { | 35 | { |
| 36 | Transmission::map_t map = Util::createEmptyMap(); | 36 | Transmission::map_t map = Util::createEmptyMap(); |
| 37 | 37 | ||
| 38 | m_actorMovements[Color::blue] = Actor::Movement( (qrand() % 4) + 1 ); | 38 | //TODO: ai |
| 39 | m_actorMovements[Color::green] = Actor::Movement( (qrand() % 4) + 1 ); | 39 | //m_actorMovements[Color::blue] = Actor::Movement((qrand() % 4) + 1); |
| 40 | //m_actorMovements[Color::green] = Actor::Movement((qrand() % 4) + 1); | ||
| 40 | 41 | ||
| 41 | QMapIterator<Color::Color, Actor::Movement> i(m_actorMovements); | 42 | QMutableMapIterator<Color::Color, Actor::Movement> i(m_actorMovements); |
| 42 | while (i.hasNext()) | 43 | while (i.hasNext()) |
| 43 | { | 44 | { |
| 44 | i.next(); | 45 | i.next(); |
| @@ -90,10 +91,11 @@ Transmission::map_t Server::calculateUpdates() | |||
| 90 | PixmapItem *item = visualMap[newMapPosition.x()][newMapPosition.y()]; | 91 | PixmapItem *item = visualMap[newMapPosition.x()][newMapPosition.y()]; |
| 91 | if (item != NULL && oldItem != item) | 92 | if (item != NULL && oldItem != item) |
| 92 | { | 93 | { |
| 93 | if (! item->checkEnter(actor)) | 94 | if (!item->checkEnter(actor)) |
| 94 | { | 95 | { |
| 95 | // movement invalid | 96 | /* movement invalid. e.g. move against wall */ |
| 96 | newMapPosition = mapPosition; | 97 | newMapPosition = mapPosition; |
| 98 | m_actorMovements[i.key()] = Actor::None; | ||
| 97 | } | 99 | } |
| 98 | else | 100 | else |
| 99 | { | 101 | { |
| @@ -107,12 +109,17 @@ Transmission::map_t Server::calculateUpdates() | |||
| 107 | } | 109 | } |
| 108 | // </t3h g4m2 10gic> | 110 | // </t3h g4m2 10gic> |
| 109 | 111 | ||
| 110 | if (mapPosition != newMapPosition) | 112 | |
| 111 | { | 113 | //map[mapPosition.x()][mapPosition.y()] = Transmission::empty; |
| 112 | //map[mapPosition.x()][mapPosition.y()] = Transmission::empty; | 114 | map[newMapPosition.x()][newMapPosition.y()] |= |
| 113 | map[newMapPosition.x()][newMapPosition.y()] |= | ||
| 114 | Transmission::pacman | i.key() | | 115 | Transmission::pacman | i.key() | |
| 115 | Util::actorMovementToTransmission(i.value()) ; | 116 | Util::actorMovementToTransmission(i.value()); |
| 117 | |||
| 118 | if (i.value() == Actor::None) | ||
| 119 | { | ||
| 120 | /* set actor to non-moving */ | ||
| 121 | m_actorMovements[i.key()] = Actor::None; | ||
| 122 | i.remove(); | ||
| 116 | } | 123 | } |
| 117 | } | 124 | } |
| 118 | return map; | 125 | return map; |
