diff options
Diffstat (limited to 'pacman-c++/common/gameentity.h')
| -rw-r--r-- | pacman-c++/common/gameentity.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/pacman-c++/common/gameentity.h b/pacman-c++/common/gameentity.h new file mode 100644 index 0000000..116fae5 --- /dev/null +++ b/pacman-c++/common/gameentity.h | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | #ifndef GAMEENTITY_H | ||
| 2 | #define GAMEENTITY_H | ||
| 3 | |||
| 4 | #include "constants.h" | ||
| 5 | #include "pixmapitem.h" | ||
| 6 | #include <QtGlobal> | ||
| 7 | #include <QDebug> | ||
| 8 | |||
| 9 | class Actor; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * Base class for entities that interact in the game | ||
| 13 | */ | ||
| 14 | class GameEntity | ||
| 15 | : public PixmapItem | ||
| 16 | { | ||
| 17 | public: | ||
| 18 | enum | ||
| 19 | { | ||
| 20 | Type = UserType + 1 | ||
| 21 | }; | ||
| 22 | |||
| 23 | enum EnteredState | ||
| 24 | { | ||
| 25 | Nothing, | ||
| 26 | DestroyedEntity, | ||
| 27 | DestroyedActor | ||
| 28 | }; | ||
| 29 | |||
| 30 | public: | ||
| 31 | GameEntity(Color::Color color = Color::none, QGraphicsItem *parent = 0); | ||
| 32 | GameEntity(QGraphicsItem *parent); | ||
| 33 | virtual ~GameEntity() | ||
| 34 | {}; | ||
| 35 | |||
| 36 | /* color of entity */ | ||
| 37 | virtual Color::Color color() | ||
| 38 | { | ||
| 39 | return m_color; | ||
| 40 | } | ||
| 41 | |||
| 42 | /* returns whether the actor may enter this field */ | ||
| 43 | virtual bool checkEnter(Actor *) | ||
| 44 | { | ||
| 45 | return true; | ||
| 46 | } | ||
| 47 | |||
| 48 | /* performs action when this actor acctually enters | ||
| 49 | * returns whether this entity survives the entering | ||
| 50 | */ | ||
| 51 | virtual EnteredState enter(Actor *) | ||
| 52 | { | ||
| 53 | /* default to no action/survive */ | ||
| 54 | return Nothing; | ||
| 55 | } | ||
| 56 | |||
| 57 | /* called when an instance acctually dies for creating effects */ | ||
| 58 | virtual void onDie(Actor *) | ||
| 59 | {}; | ||
| 60 | |||
| 61 | /* enable the use of qgraphicsitem_cast with this item */ | ||
| 62 | int type() const | ||
| 63 | { | ||
| 64 | return m_type; | ||
| 65 | } | ||
| 66 | |||
| 67 | protected: | ||
| 68 | int m_type; | ||
| 69 | Color::Color m_color; | ||
| 70 | }; | ||
| 71 | |||
| 72 | #endif // GAMEENTITY_H | ||
