diff options
| author | manuel <manuel@mausz.at> | 2011-04-11 14:53:08 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-11 14:53:08 +0200 |
| commit | 8135626bfe58cf605eda793122c049e8ec7ef31d (patch) | |
| tree | 1b21a6c595c3df5113caab286b4379589d6b826f /pacman-c++ | |
| parent | c68e77cac9558316ac16d58c0f6b888599ab021a (diff) | |
| download | foop-8135626bfe58cf605eda793122c049e8ec7ef31d.tar.gz foop-8135626bfe58cf605eda793122c049e8ec7ef31d.tar.bz2 foop-8135626bfe58cf605eda793122c049e8ec7ef31d.zip | |
minor movement improvements
Diffstat (limited to 'pacman-c++')
| -rw-r--r-- | pacman-c++/actor.cpp | 19 | ||||
| -rw-r--r-- | pacman-c++/actor.h | 8 | ||||
| -rw-r--r-- | pacman-c++/point.cpp | 7 | ||||
| -rw-r--r-- | pacman-c++/server.cpp | 13 |
4 files changed, 29 insertions, 18 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index ab860bc..43368d6 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -96,16 +96,21 @@ QSequentialAnimationGroup *Actor::setupEatingAnimation(Actor::Movement direction | |||
| 96 | return eating; | 96 | return eating; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | Color::Color Actor::getColor() | 99 | Color::Color Actor::color() |
| 100 | { | 100 | { |
| 101 | return m_color; | 101 | return m_color; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | PixmapItem &Actor::getIcon() | 104 | PixmapItem &Actor::icon() |
| 105 | { | 105 | { |
| 106 | return m_icon; | 106 | return m_icon; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | Actor::Movement Actor::direction() | ||
| 110 | { | ||
| 111 | return m_direction; | ||
| 112 | } | ||
| 113 | |||
| 109 | bool Actor::isLocal() | 114 | bool Actor::isLocal() |
| 110 | { | 115 | { |
| 111 | return m_local; | 116 | return m_local; |
| @@ -113,9 +118,8 @@ bool Actor::isLocal() | |||
| 113 | 118 | ||
| 114 | void Actor::move(Actor::Movement direction) | 119 | void Actor::move(Actor::Movement direction) |
| 115 | { | 120 | { |
| 116 | //TODO: remove? | 121 | /*if (Constants::server) |
| 117 | //if (isMoving()) | 122 | return moveByServer(direction);*/ |
| 118 | // return; | ||
| 119 | 123 | ||
| 120 | /* stop current animation */ | 124 | /* stop current animation */ |
| 121 | if (direction != m_direction) | 125 | if (direction != m_direction) |
| @@ -224,3 +228,8 @@ void Actor::finishRound() | |||
| 224 | m_roundPoints = 0; | 228 | m_roundPoints = 0; |
| 225 | } | 229 | } |
| 226 | 230 | ||
| 231 | void Actor::moveByServer(Actor::Movement direction) | ||
| 232 | { | ||
| 233 | qDebug() << "move by server"; | ||
| 234 | m_direction = direction; | ||
| 235 | } | ||
diff --git a/pacman-c++/actor.h b/pacman-c++/actor.h index 19d672b..d1875f1 100644 --- a/pacman-c++/actor.h +++ b/pacman-c++/actor.h | |||
| @@ -27,8 +27,9 @@ public: | |||
| 27 | {}; | 27 | {}; |
| 28 | 28 | ||
| 29 | QSequentialAnimationGroup *setupEatingAnimation(Actor::Movement direction); | 29 | QSequentialAnimationGroup *setupEatingAnimation(Actor::Movement direction); |
| 30 | Color::Color getColor(); | 30 | Color::Color color(); |
| 31 | PixmapItem &getIcon(); | 31 | PixmapItem &icon(); |
| 32 | Movement direction(); | ||
| 32 | bool isLocal(); | 33 | bool isLocal(); |
| 33 | void move(Movement direction); | 34 | void move(Movement direction); |
| 34 | bool isMoving(); | 35 | bool isMoving(); |
| @@ -41,6 +42,9 @@ public: | |||
| 41 | void finishRound(); | 42 | void finishRound(); |
| 42 | 43 | ||
| 43 | private: | 44 | private: |
| 45 | void moveByServer(Movement direction); | ||
| 46 | |||
| 47 | private: | ||
| 44 | QPixmap m_pix; | 48 | QPixmap m_pix; |
| 45 | Color::Color m_color; | 49 | Color::Color m_color; |
| 46 | Movement m_direction; | 50 | Movement m_direction; |
diff --git a/pacman-c++/point.cpp b/pacman-c++/point.cpp index b4eae4e..4f76007 100644 --- a/pacman-c++/point.cpp +++ b/pacman-c++/point.cpp | |||
| @@ -13,17 +13,16 @@ Point::Point(QGraphicsItem *parent) | |||
| 13 | if (pixmap == NULL) | 13 | if (pixmap == NULL) |
| 14 | pixmap = new QPixmap(":/points"); | 14 | pixmap = new QPixmap(":/points"); |
| 15 | setPixmap(*pixmap); | 15 | setPixmap(*pixmap); |
| 16 | |||
| 17 | //setSprite(rand * 20 + Constants::sprite_margin, Constants::sprite_margin, Constants::field_size.width, Constants::field_size.height); | ||
| 18 | } | 16 | } |
| 19 | 17 | ||
| 20 | bool Point::enter(Actor* actor) | 18 | bool Point::enter(Actor *actor) |
| 21 | { | 19 | { |
| 22 | actor->addRoundPoints(Constants::Game::point_value); | 20 | actor->addRoundPoints(Constants::Game::point_value); |
| 23 | m_eaten = true; | 21 | m_eaten = true; |
| 24 | return false; | 22 | return false; |
| 25 | } | 23 | } |
| 26 | 24 | ||
| 27 | void Point::onDie(Actor* actor) | 25 | void Point::onDie(Actor *actor) |
| 28 | { | 26 | { |
| 27 | //TODO | ||
| 29 | } | 28 | } |
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 8b07882..b054804 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -44,8 +44,7 @@ Transmission::map_t Server::calculateUpdates() | |||
| 44 | { | 44 | { |
| 45 | i.next(); | 45 | i.next(); |
| 46 | Actor *actor = m_actors.value(i.key()); | 46 | Actor *actor = m_actors.value(i.key()); |
| 47 | QPoint mapPosition = actor->pos().toPoint(); | 47 | QPoint mapPosition = CoordToMapPosition(actor->pos().toPoint()); |
| 48 | mapPosition = CoordToMapPosition(actor->pos().toPoint()); | ||
| 49 | qDebug() << "actor " << i.key() << " is at " << mapPosition << "moving " << i.value(); | 48 | qDebug() << "actor " << i.key() << " is at " << mapPosition << "moving " << i.value(); |
| 50 | 49 | ||
| 51 | QPoint newMapPosition = mapPosition; | 50 | QPoint newMapPosition = mapPosition; |
| @@ -87,6 +86,7 @@ Transmission::map_t Server::calculateUpdates() | |||
| 87 | if (oldItem->eaten()) | 86 | if (oldItem->eaten()) |
| 88 | map[mapPosition.x()][mapPosition.y()] = Transmission::empty; | 87 | map[mapPosition.x()][mapPosition.y()] = Transmission::empty; |
| 89 | } | 88 | } |
| 89 | |||
| 90 | // new item | 90 | // new item |
| 91 | PixmapItem *item = visualMap[newMapPosition.x()][newMapPosition.y()]; | 91 | PixmapItem *item = visualMap[newMapPosition.x()][newMapPosition.y()]; |
| 92 | if (item != NULL && oldItem != item) | 92 | if (item != NULL && oldItem != item) |
| @@ -95,7 +95,6 @@ Transmission::map_t Server::calculateUpdates() | |||
| 95 | { | 95 | { |
| 96 | /* movement invalid. e.g. move against wall */ | 96 | /* movement invalid. e.g. move against wall */ |
| 97 | newMapPosition = mapPosition; | 97 | newMapPosition = mapPosition; |
| 98 | m_actorMovements[i.key()] = Actor::None; | ||
| 99 | } | 98 | } |
| 100 | else | 99 | else |
| 101 | { | 100 | { |
| @@ -109,11 +108,11 @@ Transmission::map_t Server::calculateUpdates() | |||
| 109 | } | 108 | } |
| 110 | // </t3h g4m2 10gic> | 109 | // </t3h g4m2 10gic> |
| 111 | 110 | ||
| 111 | if (mapPosition == newMapPosition) | ||
| 112 | m_actorMovements[i.key()] = Actor::None; | ||
| 112 | 113 | ||
| 113 | //map[mapPosition.x()][mapPosition.y()] = Transmission::empty; | 114 | map[newMapPosition.x()][newMapPosition.y()] |= Transmission::pacman | |
| 114 | map[newMapPosition.x()][newMapPosition.y()] |= | 115 | i.key() | Util::actorMovementToTransmission(i.value()); |
| 115 | Transmission::pacman | i.key() | | ||
| 116 | Util::actorMovementToTransmission(i.value()); | ||
| 117 | 116 | ||
| 118 | if (i.value() == Actor::None) | 117 | if (i.value() == Actor::None) |
| 119 | { | 118 | { |
