diff options
| author | totycro <totycro@unknown-horizons.org> | 2011-04-11 12:37:29 +0200 |
|---|---|---|
| committer | totycro <totycro@unknown-horizons.org> | 2011-04-11 12:37:29 +0200 |
| commit | 51a3559e5df31018d7de14357f83c24e7e508d7e (patch) | |
| tree | 89db0899d182dd5b3b770b07c8646dd80c915d4e | |
| parent | 98f4a31e1a359a69dbcc0fa4055f36cefb6d4e02 (diff) | |
| download | foop-51a3559e5df31018d7de14357f83c24e7e508d7e.tar.gz foop-51a3559e5df31018d7de14357f83c24e7e508d7e.tar.bz2 foop-51a3559e5df31018d7de14357f83c24e7e508d7e.zip | |
progress
| -rw-r--r-- | pacman-c++/bonuspoint.cpp | 5 | ||||
| -rw-r--r-- | pacman-c++/bonuspoint.h | 2 | ||||
| -rw-r--r-- | pacman-c++/gameentity.h | 16 | ||||
| -rw-r--r-- | pacman-c++/pacman.pro | 3 | ||||
| -rw-r--r-- | pacman-c++/pacman.server.pro | 3 | ||||
| -rw-r--r-- | pacman-c++/pixmapitem.h | 5 | ||||
| -rw-r--r-- | pacman-c++/point.cpp | 4 | ||||
| -rw-r--r-- | pacman-c++/point.h | 2 | ||||
| -rw-r--r-- | pacman-c++/sceneholder.cpp | 21 | ||||
| -rw-r--r-- | pacman-c++/server.cpp | 19 |
10 files changed, 56 insertions, 24 deletions
diff --git a/pacman-c++/bonuspoint.cpp b/pacman-c++/bonuspoint.cpp index 3a72243..2a772d5 100644 --- a/pacman-c++/bonuspoint.cpp +++ b/pacman-c++/bonuspoint.cpp | |||
| @@ -20,7 +20,10 @@ BonusPoint::BonusPoint(QGraphicsItem *parent) | |||
| 20 | setSprite(rand * 20 + Constants::sprite_margin, Constants::sprite_margin, Constants::field_size.width, Constants::field_size.height); | 20 | setSprite(rand * 20 + Constants::sprite_margin, Constants::sprite_margin, Constants::field_size.width, Constants::field_size.height); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | void BonusPoint::enter(Actor* actor) | 23 | bool BonusPoint::enter(Actor* actor) |
| 24 | { | 24 | { |
| 25 | actor->addRoundPoints(Constants::Game::bonus_point_value); | 25 | actor->addRoundPoints(Constants::Game::bonus_point_value); |
| 26 | actor->eatingCherry(); | ||
| 27 | m_eaten = true; | ||
| 28 | return false; | ||
| 26 | } | 29 | } |
diff --git a/pacman-c++/bonuspoint.h b/pacman-c++/bonuspoint.h index 2c5f7ea..dcf561e 100644 --- a/pacman-c++/bonuspoint.h +++ b/pacman-c++/bonuspoint.h | |||
| @@ -11,7 +11,7 @@ public: | |||
| 11 | virtual ~BonusPoint() | 11 | virtual ~BonusPoint() |
| 12 | {}; | 12 | {}; |
| 13 | 13 | ||
| 14 | virtual void enter(Actor *actor); | 14 | virtual bool enter(Actor *actor); |
| 15 | }; | 15 | }; |
| 16 | 16 | ||
| 17 | #endif // BONUSPOINT_H | 17 | #endif // BONUSPOINT_H |
diff --git a/pacman-c++/gameentity.h b/pacman-c++/gameentity.h index 82df438..2a771ee 100644 --- a/pacman-c++/gameentity.h +++ b/pacman-c++/gameentity.h | |||
| @@ -1,19 +1,29 @@ | |||
| 1 | #ifndef GAMEENTITY_H | 1 | #ifndef GAMEENTITY_H |
| 2 | #define GAMEENTITY_H | 2 | #define GAMEENTITY_H |
| 3 | 3 | ||
| 4 | #include <QtGlobal> | ||
| 5 | |||
| 4 | class Actor; | 6 | class Actor; |
| 5 | 7 | ||
| 6 | /** | 8 | /** |
| 7 | * Abstract base class for entities that interact in the game | 9 | * Base class for entities that interact in the game |
| 8 | */ | 10 | */ |
| 9 | class GameEntity { | 11 | class GameEntity { |
| 12 | public: | ||
| 13 | GameEntity(); | ||
| 14 | virtual ~GameEntity() {}; | ||
| 10 | 15 | ||
| 11 | // returns whether the actor may enter this field | 16 | // returns whether the actor may enter this field |
| 12 | virtual bool checkEnter(Actor *actor) = 0; | 17 | virtual bool checkEnter(Actor *actor) { Q_UNUSED(actor); return true; } // default to true |
| 13 | 18 | ||
| 14 | // performs action when this actor acctually enters | 19 | // performs action when this actor acctually enters |
| 15 | virtual void enter(Actor *actor) = 0; | 20 | // returns whether this entity survives the entering |
| 21 | virtual bool enter(Actor *actor) { Q_UNUSED(actor); return true; } // default to no action/survive | ||
| 22 | |||
| 23 | virtual bool eaten() { return m_eaten; } | ||
| 16 | 24 | ||
| 25 | protected: | ||
| 26 | bool m_eaten; | ||
| 17 | }; | 27 | }; |
| 18 | 28 | ||
| 19 | #endif // GAMEENTITY_H | 29 | #endif // GAMEENTITY_H |
diff --git a/pacman-c++/pacman.pro b/pacman-c++/pacman.pro index a36ef37..07efc71 100644 --- a/pacman-c++/pacman.pro +++ b/pacman-c++/pacman.pro | |||
| @@ -14,7 +14,8 @@ SOURCES += pixmapitem.cpp \ | |||
| 14 | audio.cpp \ | 14 | audio.cpp \ |
| 15 | clicklabel.cpp \ | 15 | clicklabel.cpp \ |
| 16 | sceneholder.cpp \ | 16 | sceneholder.cpp \ |
| 17 | util.cpp | 17 | util.cpp \ |
| 18 | gameentity.cpp | ||
| 18 | HEADERS += pixmapitem.h \ | 19 | HEADERS += pixmapitem.h \ |
| 19 | actor.h \ | 20 | actor.h \ |
| 20 | animationmanager.h \ | 21 | animationmanager.h \ |
diff --git a/pacman-c++/pacman.server.pro b/pacman-c++/pacman.server.pro index 172045d..0b5fd6d 100644 --- a/pacman-c++/pacman.server.pro +++ b/pacman-c++/pacman.server.pro | |||
| @@ -17,7 +17,8 @@ SOURCES += pixmapitem.cpp \ | |||
| 17 | audio.cpp \ | 17 | audio.cpp \ |
| 18 | sceneholder.cpp \ | 18 | sceneholder.cpp \ |
| 19 | util.cpp \ | 19 | util.cpp \ |
| 20 | clicklabel.cpp | 20 | clicklabel.cpp \ |
| 21 | gameentity.cpp | ||
| 21 | HEADERS += pixmapitem.h \ | 22 | HEADERS += pixmapitem.h \ |
| 22 | actor.h \ | 23 | actor.h \ |
| 23 | animationmanager.h \ | 24 | animationmanager.h \ |
diff --git a/pacman-c++/pixmapitem.h b/pacman-c++/pixmapitem.h index 88770d2..4e58a52 100644 --- a/pacman-c++/pixmapitem.h +++ b/pacman-c++/pixmapitem.h | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #include "gameentity.h" | 7 | #include "gameentity.h" |
| 8 | 8 | ||
| 9 | class PixmapItem | 9 | class PixmapItem |
| 10 | : public QGraphicsObject, GameEntity | 10 | : public QGraphicsObject, public GameEntity |
| 11 | { | 11 | { |
| 12 | public: | 12 | public: |
| 13 | PixmapItem(QGraphicsItem *parent = 0); | 13 | PixmapItem(QGraphicsItem *parent = 0); |
| @@ -25,9 +25,6 @@ public: | |||
| 25 | QPainterPath shape() const; | 25 | QPainterPath shape() const; |
| 26 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); | 26 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); |
| 27 | 27 | ||
| 28 | virtual bool checkEnter(Actor *actor) { Q_UNUSED(actor); return true; } // default to true | ||
| 29 | virtual void enter(Actor *actor) { Q_UNUSED(actor); } // default to no action | ||
| 30 | |||
| 31 | private: | 28 | private: |
| 32 | QPixmap m_pix; | 29 | QPixmap m_pix; |
| 33 | int m_x, m_y; | 30 | int m_x, m_y; |
diff --git a/pacman-c++/point.cpp b/pacman-c++/point.cpp index 67a7e5f..05bd277 100644 --- a/pacman-c++/point.cpp +++ b/pacman-c++/point.cpp | |||
| @@ -17,7 +17,9 @@ Point::Point(QGraphicsItem *parent) | |||
| 17 | //setSprite(rand * 20 + Constants::sprite_margin, Constants::sprite_margin, Constants::field_size.width, Constants::field_size.height); | 17 | //setSprite(rand * 20 + Constants::sprite_margin, Constants::sprite_margin, Constants::field_size.width, Constants::field_size.height); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | void Point::enter(Actor* actor) | 20 | bool Point::enter(Actor* actor) |
| 21 | { | 21 | { |
| 22 | actor->addRoundPoints(Constants::Game::point_value); | 22 | actor->addRoundPoints(Constants::Game::point_value); |
| 23 | m_eaten = true; | ||
| 24 | return false; | ||
| 23 | } | 25 | } |
diff --git a/pacman-c++/point.h b/pacman-c++/point.h index 0e0152d..033ca56 100644 --- a/pacman-c++/point.h +++ b/pacman-c++/point.h | |||
| @@ -11,7 +11,7 @@ public: | |||
| 11 | virtual ~Point() | 11 | virtual ~Point() |
| 12 | {}; | 12 | {}; |
| 13 | 13 | ||
| 14 | virtual void enter(Actor *actor); | 14 | virtual bool enter(Actor *actor); |
| 15 | }; | 15 | }; |
| 16 | 16 | ||
| 17 | #endif // POINT_H | 17 | #endif // POINT_H |
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index 0a65d19..1596ba1 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp | |||
| @@ -31,12 +31,9 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 31 | 31 | ||
| 32 | Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); | 32 | Color::Color color = static_cast<Color::Color>(cur & Transmission::color_mask); |
| 33 | PixmapItem* item = NULL; | 33 | PixmapItem* item = NULL; |
| 34 | if (cur == Transmission::none) | 34 | |
| 35 | { | 35 | if (cur & Transmission::empty) |
| 36 | // no update | 36 | { // special handling for purging field |
| 37 | } | ||
| 38 | else if (cur & Transmission::empty) | ||
| 39 | { | ||
| 40 | PixmapItem* oldItem = visualMap[x][y]; | 37 | PixmapItem* oldItem = visualMap[x][y]; |
| 41 | // remove elements (in case it's not an actor) | 38 | // remove elements (in case it's not an actor) |
| 42 | if (oldItem != NULL && dynamic_cast<Actor*>(item) == NULL) | 39 | if (oldItem != NULL && dynamic_cast<Actor*>(item) == NULL) |
| @@ -44,8 +41,14 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 44 | m_scene->removeItem(oldItem); | 41 | m_scene->removeItem(oldItem); |
| 45 | visualMap[x][y] = NULL; | 42 | visualMap[x][y] = NULL; |
| 46 | delete oldItem; | 43 | delete oldItem; |
| 44 | qDebug() << "deleting " << x << y; | ||
| 47 | } | 45 | } |
| 48 | } | 46 | } |
| 47 | |||
| 48 | if (cur == Transmission::none) | ||
| 49 | { | ||
| 50 | // no update | ||
| 51 | } | ||
| 49 | else if (cur & Transmission::block) | 52 | else if (cur & Transmission::block) |
| 50 | { | 53 | { |
| 51 | unsigned int neighbours = Block::None; | 54 | unsigned int neighbours = Block::None; |
| @@ -81,7 +84,11 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 81 | Actor::Movement direction = | 84 | Actor::Movement direction = |
| 82 | Util::transmissionMovementToActor(cur & Transmission::direction_mask); | 85 | Util::transmissionMovementToActor(cur & Transmission::direction_mask); |
| 83 | actor->move(direction); | 86 | actor->move(direction); |
| 84 | qDebug() << "actor move " << direction; | 87 | qDebug() << "actor move " << direction << "to " << x << y; |
| 88 | } | ||
| 89 | else if (cur & Transmission::empty) | ||
| 90 | { | ||
| 91 | // already handled | ||
| 85 | } | 92 | } |
| 86 | else | 93 | else |
| 87 | { | 94 | { |
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index b631345..4656238 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -75,20 +75,31 @@ Transmission::map_t Server::calculateUpdates() | |||
| 75 | 75 | ||
| 76 | // <t3h g4m3 10gic> | 76 | // <t3h g4m3 10gic> |
| 77 | // TODO: support actors eating each other | 77 | // TODO: support actors eating each other |
| 78 | // old item | ||
| 79 | PixmapItem *oldItem = visualMap[mapPosition.x()][mapPosition.y()]; | ||
| 80 | if (oldItem != NULL) { | ||
| 81 | if (oldItem->eaten()) { | ||
| 82 | map[mapPosition.x()][mapPosition.y()] = Transmission::empty; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | // new item | ||
| 78 | PixmapItem *item = visualMap[newMapPosition.x()][newMapPosition.y()]; | 86 | PixmapItem *item = visualMap[newMapPosition.x()][newMapPosition.y()]; |
| 79 | if (item != NULL) { | 87 | if (item != NULL && oldItem != item) { |
| 80 | if (! item->checkEnter(actor)) { // movement invalid | 88 | if (! item->checkEnter(actor)) { // movement invalid |
| 81 | newMapPosition = mapPosition; | 89 | newMapPosition = mapPosition; |
| 82 | } else { // apply actions of entering this field | 90 | } else { // apply actions of entering this field |
| 83 | item->enter(actor); | 91 | bool survive = item->enter(actor); |
| 92 | if (!survive) { | ||
| 93 | //map[newMapPosition.x()][newMapPosition.y()] = Transmission::empty; | ||
| 94 | } | ||
| 84 | } | 95 | } |
| 85 | } | 96 | } |
| 86 | // </t3h g4m2 10gic> | 97 | // </t3h g4m2 10gic> |
| 87 | 98 | ||
| 88 | if (mapPosition != newMapPosition) | 99 | if (mapPosition != newMapPosition) |
| 89 | { | 100 | { |
| 90 | map[mapPosition.x()][mapPosition.y()] = Transmission::empty; | 101 | //map[mapPosition.x()][mapPosition.y()] = Transmission::empty; |
| 91 | map[newMapPosition.x()][newMapPosition.y()] = | 102 | map[newMapPosition.x()][newMapPosition.y()] |= |
| 92 | Transmission::pacman | i.key() | | 103 | Transmission::pacman | i.key() | |
| 93 | Util::actorMovementToTransmission(i.value()) ; | 104 | Util::actorMovementToTransmission(i.value()) ; |
| 94 | } | 105 | } |
