diff options
| -rw-r--r-- | pacman-c++/bonuspoint.cpp | 2 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 3 | ||||
| -rw-r--r-- | pacman-c++/sceneholder.cpp | 16 | ||||
| -rw-r--r-- | pacman-c++/sceneholder.h | 4 | ||||
| -rw-r--r-- | pacman-c++/server.cpp | 12 | ||||
| -rw-r--r-- | pacman-c++/server.h | 7 | ||||
| -rw-r--r-- | pacman-c++/util.cpp | 7 |
7 files changed, 32 insertions, 19 deletions
diff --git a/pacman-c++/bonuspoint.cpp b/pacman-c++/bonuspoint.cpp index 8cb8c7e..c90cccc 100644 --- a/pacman-c++/bonuspoint.cpp +++ b/pacman-c++/bonuspoint.cpp | |||
| @@ -26,7 +26,7 @@ BonusPoint::BonusPoint(QGraphicsItem *parent) | |||
| 26 | setSprite(rand * 20 + Constants::sprite_margin, Constants::sprite_margin, Constants::field_size.width, Constants::field_size.height); | 26 | setSprite(rand * 20 + Constants::sprite_margin, Constants::sprite_margin, Constants::field_size.width, Constants::field_size.height); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | bool BonusPoint::enter(Actor* actor) | 29 | bool BonusPoint::enter(Actor *actor) |
| 30 | { | 30 | { |
| 31 | actor->addRoundPoints(Constants::Game::bonus_point_value); | 31 | actor->addRoundPoints(Constants::Game::bonus_point_value); |
| 32 | m_eaten = true; | 32 | m_eaten = true; |
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index f81961f..82099c4 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -80,8 +80,6 @@ void MainWidget::createGui() | |||
| 80 | scoreLayout->addWidget(scoreBox); | 80 | scoreLayout->addWidget(scoreBox); |
| 81 | } | 81 | } |
| 82 | layout->addLayout(scoreLayout); | 82 | layout->addLayout(scoreLayout); |
| 83 | /* add some margin to scorebox hopefully won't resize the window */ | ||
| 84 | //setMinimumWidth(scoreLayout->minimumSize().width() + 50); | ||
| 85 | 83 | ||
| 86 | QGraphicsView *window = new QGraphicsView(m_scene, this); | 84 | QGraphicsView *window = new QGraphicsView(m_scene, this); |
| 87 | window->setFrameStyle(0); | 85 | window->setFrameStyle(0); |
| @@ -151,6 +149,7 @@ void MainWidget::tick() | |||
| 151 | if (m_updatepacket.eating_order_size() > 0) | 149 | if (m_updatepacket.eating_order_size() > 0) |
| 152 | { | 150 | { |
| 153 | Q_ASSERT(m_scene != NULL); | 151 | Q_ASSERT(m_scene != NULL); |
| 152 | m_scene->removeActors(); | ||
| 154 | QList<Color::Color> order; | 153 | QList<Color::Color> order; |
| 155 | for(int i = 0; i < m_updatepacket.eating_order_size(); ++i) | 154 | for(int i = 0; i < m_updatepacket.eating_order_size(); ++i) |
| 156 | order.append(static_cast<Color::Color>(m_updatepacket.eating_order(i) & Transmission::color_mask)); | 155 | order.append(static_cast<Color::Color>(m_updatepacket.eating_order(i) & Transmission::color_mask)); |
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index 03abf7f..1610b7e 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp | |||
| @@ -150,11 +150,6 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x | |||
| 150 | qDebug() << "[SceneUpdate] actor moves: color=" << color | 150 | qDebug() << "[SceneUpdate] actor moves: color=" << color |
| 151 | << "direction=" << direction << "newpos=" << QPoint(x, y); | 151 | << "direction=" << direction << "newpos=" << QPoint(x, y); |
| 152 | } | 152 | } |
| 153 | |||
| 154 | QPoint distance = QPoint(x, y) - CoordToMapPosition(actor->pos().x(), actor->pos().y()); | ||
| 155 | if (distance.manhattanLength() > 1) { | ||
| 156 | actor->setPos(mapPositionToCoord(x, y)); | ||
| 157 | } | ||
| 158 | } | 153 | } |
| 159 | 154 | ||
| 160 | if (cur & Transmission::empty) | 155 | if (cur & Transmission::empty) |
| @@ -213,6 +208,16 @@ QList<Color::Color> &SceneHolder::eatingOrder() | |||
| 213 | return m_eatingorder; | 208 | return m_eatingorder; |
| 214 | } | 209 | } |
| 215 | 210 | ||
| 211 | void SceneHolder::removeActors() | ||
| 212 | { | ||
| 213 | foreach(Actor *actor, m_actors) | ||
| 214 | { | ||
| 215 | removeItem(actor); | ||
| 216 | delete actor; | ||
| 217 | } | ||
| 218 | m_actors.clear(); | ||
| 219 | } | ||
| 220 | |||
| 216 | QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) | 221 | QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) |
| 217 | { | 222 | { |
| 218 | return QPoint(x * Constants::field_size.width, y * Constants::field_size.height); | 223 | return QPoint(x * Constants::field_size.width, y * Constants::field_size.height); |
| @@ -232,4 +237,3 @@ QPoint SceneHolder::CoordToMapPosition(QPoint point) | |||
| 232 | { | 237 | { |
| 233 | return CoordToMapPosition(point.x(), point.y()); | 238 | return CoordToMapPosition(point.x(), point.y()); |
| 234 | } | 239 | } |
| 235 | |||
diff --git a/pacman-c++/sceneholder.h b/pacman-c++/sceneholder.h index 26ba942..c61de58 100644 --- a/pacman-c++/sceneholder.h +++ b/pacman-c++/sceneholder.h | |||
| @@ -23,6 +23,7 @@ public: | |||
| 23 | Color::Color color(); | 23 | Color::Color color(); |
| 24 | void setEatingOrder(QList<Color::Color> &order); | 24 | void setEatingOrder(QList<Color::Color> &order); |
| 25 | QList<Color::Color> &eatingOrder(); | 25 | QList<Color::Color> &eatingOrder(); |
| 26 | void removeActors(); | ||
| 26 | 27 | ||
| 27 | signals: | 28 | signals: |
| 28 | void allPointsRemoved(); | 29 | void allPointsRemoved(); |
| @@ -37,11 +38,12 @@ protected: | |||
| 37 | QPoint CoordToMapPosition(unsigned int x, unsigned int y); | 38 | QPoint CoordToMapPosition(unsigned int x, unsigned int y); |
| 38 | QPoint CoordToMapPosition(QPoint point); | 39 | QPoint CoordToMapPosition(QPoint point); |
| 39 | 40 | ||
| 41 | protected: | ||
| 40 | /* map of all pixmap instances */ | 42 | /* map of all pixmap instances */ |
| 41 | QVector< QVector<GameEntity *> > visualMap; | 43 | QVector< QVector<GameEntity *> > visualMap; |
| 42 | 44 | ||
| 43 | /* map of actors in order to keep track of those instances */ | 45 | /* map of actors in order to keep track of those instances */ |
| 44 | QMap<Color::Color, Actor*> m_actors; | 46 | QMap<Color::Color, Actor *> m_actors; |
| 45 | 47 | ||
| 46 | /* items that got removed/has been eaten | 48 | /* items that got removed/has been eaten |
| 47 | * must be remove one tick later | 49 | * must be remove one tick later |
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index f2c0f1c..72ee995 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -31,7 +31,7 @@ bool Server::run() | |||
| 31 | if (!waitForClientConnections()) | 31 | if (!waitForClientConnections()) |
| 32 | return false; | 32 | return false; |
| 33 | 33 | ||
| 34 | initRoundMap(true); | 34 | initRoundMap(); |
| 35 | 35 | ||
| 36 | m_tickTimer = new QTimer(this); | 36 | m_tickTimer = new QTimer(this); |
| 37 | connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); | 37 | connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); |
| @@ -484,6 +484,7 @@ void Server::keyPressUpdate() | |||
| 484 | 484 | ||
| 485 | void Server::onRoundFinished() | 485 | void Server::onRoundFinished() |
| 486 | { | 486 | { |
| 487 | // TODO: call this when a pacman get's eaten | ||
| 487 | foreach(Actor *actor, m_actors) | 488 | foreach(Actor *actor, m_actors) |
| 488 | actor->finishRound(); | 489 | actor->finishRound(); |
| 489 | 490 | ||
| @@ -495,8 +496,10 @@ void Server::onRoundFinished() | |||
| 495 | m_tickTimer->stop(); | 496 | m_tickTimer->stop(); |
| 496 | } | 497 | } |
| 497 | 498 | ||
| 498 | void Server::initRoundMap(bool firstPacket) | 499 | void Server::initRoundMap() |
| 499 | { | 500 | { |
| 501 | /* delete actors first */ | ||
| 502 | removeActors(); | ||
| 500 | 503 | ||
| 501 | /* create new map */ | 504 | /* create new map */ |
| 502 | Transmission::map_t map = Util::createDemoMap(); | 505 | Transmission::map_t map = Util::createDemoMap(); |
| @@ -516,12 +519,11 @@ void Server::initRoundMap(bool firstPacket) | |||
| 516 | } | 519 | } |
| 517 | 520 | ||
| 518 | updateMap(map); | 521 | updateMap(map); |
| 519 | sendUpdate(map, firstPacket); | 522 | sendUpdate(map, true); |
| 520 | Util::deleteMap(map); | 523 | Util::deleteMap(map); |
| 521 | map = NULL; | 524 | map = NULL; |
| 522 | 525 | ||
| 523 | if (firstPacket) | 526 | connect(this, SIGNAL(allPointsRemoved()), this, SLOT(onRoundFinished()), Qt::UniqueConnection); |
| 524 | connect(this, SIGNAL(allPointsRemoved()), this, SLOT(onRoundFinished())); | ||
| 525 | } | 527 | } |
| 526 | 528 | ||
| 527 | bool Server::parseCommandline() | 529 | bool Server::parseCommandline() |
diff --git a/pacman-c++/server.h b/pacman-c++/server.h index dc8de88..6dd138b 100644 --- a/pacman-c++/server.h +++ b/pacman-c++/server.h | |||
| @@ -37,12 +37,11 @@ protected: | |||
| 37 | QPoint addRandomPoint(Transmission::map_t map, Transmission::field_t type = Transmission::bonuspoint); | 37 | QPoint addRandomPoint(Transmission::map_t map, Transmission::field_t type = Transmission::bonuspoint); |
| 38 | void colorizeBlocks(Transmission::map_t map); | 38 | void colorizeBlocks(Transmission::map_t map); |
| 39 | void botCalculate(Actor *actor); | 39 | void botCalculate(Actor *actor); |
| 40 | void initRoundMap(); | ||
| 40 | 41 | ||
| 41 | protected slots: | 42 | protected slots: |
| 42 | // TODO: call this when a pacman get's eaten | 43 | /* called when a round is finished */ |
| 43 | void onRoundFinished(); // called when a round is finished | 44 | void onRoundFinished(); |
| 44 | protected: | ||
| 45 | void initRoundMap(bool firstPacket = false); // creates new round map | ||
| 46 | 45 | ||
| 47 | protected: | 46 | protected: |
| 48 | QMap<Color::Color, QTcpSocket *> m_clientConnections; | 47 | QMap<Color::Color, QTcpSocket *> m_clientConnections; |
diff --git a/pacman-c++/util.cpp b/pacman-c++/util.cpp index d83ea3c..f8396f9 100644 --- a/pacman-c++/util.cpp +++ b/pacman-c++/util.cpp | |||
| @@ -145,7 +145,14 @@ namespace Util | |||
| 145 | { | 145 | { |
| 146 | Transmission::field_t &cur = map[x][y]; | 146 | Transmission::field_t &cur = map[x][y]; |
| 147 | if (cur == Transmission::none) | 147 | if (cur == Transmission::none) |
| 148 | { | ||
| 149 | #if 0 | ||
| 150 | /* use for endround testing */ | ||
| 151 | if (x > 0) | ||
| 152 | continue; | ||
| 153 | #endif | ||
| 148 | cur = type; | 154 | cur = type; |
| 155 | } | ||
| 149 | else if (cur == Transmission::point) | 156 | else if (cur == Transmission::point) |
| 150 | cur = Transmission::none; | 157 | cur = Transmission::none; |
| 151 | } | 158 | } |
