From 6c44b14d2bae2120c069ab205f95b2e51de2caea Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 11 Apr 2011 13:42:28 +0200 Subject: make constants::server extern code cleanup --- pacman-c++/actor.cpp | 2 +- pacman-c++/block.h | 10 +++++++--- pacman-c++/client.cpp | 2 ++ pacman-c++/constants.h | 2 +- pacman-c++/gameentity.cpp | 1 - pacman-c++/gameentity.h | 47 ++++++++++++++++++++++++++++++---------------- pacman-c++/sceneholder.cpp | 6 ++++-- pacman-c++/server.cpp | 23 +++++++++++++++-------- 8 files changed, 61 insertions(+), 32 deletions(-) (limited to 'pacman-c++') diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index e34d338..a97232f 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp @@ -89,7 +89,7 @@ QSequentialAnimationGroup *Actor::setupEatingAnimation(Actor::Movement direction fadeout->setEndValue(false); QPropertyAnimation *move = new QPropertyAnimation(img, "pos", m_moving); - move->setDuration(Constants::tick - 20); //TODO + move->setDuration(Constants::tick - 50); //TODO move->setEndValue(QPoint(0, 0)); } diff --git a/pacman-c++/block.h b/pacman-c++/block.h index b5a4bf3..9e49a7d 100644 --- a/pacman-c++/block.h +++ b/pacman-c++/block.h @@ -9,7 +9,8 @@ class Block : public PixmapItem { public: - enum Neighbour { + enum Neighbour + { None = 0, Left = (1 << 0), Right = (1 << 1), @@ -23,8 +24,11 @@ public: {}; void setNeighbours(unsigned int neighbours); - - virtual bool checkEnter(Actor *actor) { Q_UNUSED(actor); return false; } // TODO: colored blocks + virtual bool checkEnter(Actor *) + { + /* TODO: colored blocks */ + return false; + } private: // map for saving QPixmaps for reuse diff --git a/pacman-c++/client.cpp b/pacman-c++/client.cpp index d885e49..3d45ebd 100644 --- a/pacman-c++/client.cpp +++ b/pacman-c++/client.cpp @@ -63,6 +63,8 @@ void Client::mutedChanged(bool muted) const m_settings->setValue("muted", muted); } +bool Constants::server = false; + int main(int argc, char ** argv) { GOOGLE_PROTOBUF_VERIFY_VERSION; diff --git a/pacman-c++/constants.h b/pacman-c++/constants.h index 90963fe..15eba86 100644 --- a/pacman-c++/constants.h +++ b/pacman-c++/constants.h @@ -15,7 +15,7 @@ namespace Constants { const unsigned int sprite_margin = 2; const unsigned int sprite_offset = 20; const unsigned int tick = 250; // ms - static bool server = false; + extern bool server; namespace Networking { diff --git a/pacman-c++/gameentity.cpp b/pacman-c++/gameentity.cpp index e8743df..ec43d93 100644 --- a/pacman-c++/gameentity.cpp +++ b/pacman-c++/gameentity.cpp @@ -5,6 +5,5 @@ GameEntity::GameEntity() : m_eaten(false) { - } diff --git a/pacman-c++/gameentity.h b/pacman-c++/gameentity.h index 0c0ab9c..afa3aba 100644 --- a/pacman-c++/gameentity.h +++ b/pacman-c++/gameentity.h @@ -8,24 +8,39 @@ class Actor; /** * Base class for entities that interact in the game */ -class GameEntity { +class GameEntity +{ public: GameEntity(); - virtual ~GameEntity() {}; - - // returns whether the actor may enter this field - virtual bool checkEnter(Actor *actor) { Q_UNUSED(actor); return true; } // default to true - - // performs action when this actor acctually enters - // returns whether this entity survives the entering - virtual bool enter(Actor *actor) { Q_UNUSED(actor); return true; } // default to no action/survive - - // check whether this entity is regarded as eaten - // (and can be removed in the next tick) - virtual bool eaten() { return m_eaten; } - - // called when an instance acctually dies for creating effects - virtual void onDie(Actor *actor) { Q_UNUSED(actor); }; + virtual ~GameEntity() + {}; + + /* returns whether the actor may enter this field */ + virtual bool checkEnter(Actor *) + { + return true; + } + + /* performs action when this actor acctually enters + * returns whether this entity survives the entering + */ + virtual bool enter(Actor *) + { + /* default to no action/survive */ + return true; + } + + /* check whether this entity is regarded as eaten + * (and can be removed in the next tick) + */ + virtual bool eaten() + { + return m_eaten; + } + + /* called when an instance acctually dies for creating effects */ + virtual void onDie(Actor *) + {}; protected: diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index 26f74a7..0047e59 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp @@ -41,8 +41,10 @@ void SceneHolder::updateMap(const Transmission::map_t& map) m_scene->removeItem(oldItem); visualMap[x][y] = NULL; Actor *actor = NULL; - foreach (Actor *i, m_actors) { - if (CoordToMapPosition(i->pos().x(), i->pos().y()) == QPoint(x, y)) { + foreach (Actor *i, m_actors) + { + if (CoordToMapPosition(i->pos().toPoint()) == QPoint(x, y)) + { actor = i; break; } diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 43aa6ff..965517e 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp @@ -81,19 +81,26 @@ Transmission::map_t Server::calculateUpdates() // TODO: support actors eating each other // old item PixmapItem *oldItem = visualMap[mapPosition.x()][mapPosition.y()]; - if (oldItem != NULL) { - if (oldItem->eaten()) { + if (oldItem != NULL) + { + if (oldItem->eaten()) map[mapPosition.x()][mapPosition.y()] = Transmission::empty; - } } // new item PixmapItem *item = visualMap[newMapPosition.x()][newMapPosition.y()]; - if (item != NULL && oldItem != item) { - if (! item->checkEnter(actor)) { // movement invalid + if (item != NULL && oldItem != item) + { + if (! item->checkEnter(actor)) + { + // movement invalid newMapPosition = mapPosition; - } else { // apply actions of entering this field + } + else + { + // apply actions of entering this field bool survive = item->enter(actor); - if (!survive) { + if (!survive) + { //map[newMapPosition.x()][newMapPosition.y()] = Transmission::empty; } } @@ -197,6 +204,7 @@ void Server::keyPressUpdate() } } +bool Constants::server = true; int main(int argc, char ** argv) { @@ -208,7 +216,6 @@ int main(int argc, char ** argv) qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); - Constants::server = true; Server Server; return app.exec(); } -- cgit v1.2.3