1 #ifndef GAMEITEM_H
2 #define GAMEITEM_H
3 
4 #include <QtGui>
5 
6 #include "defines.h"
7 
8 const int MAX_ITEMS_COUNT     = 6;
9 
10 const int ITEM_JOCKER         = (1 << 4);
11 const int ITEM_FALLER         = (1 << 5);
12 
13 const int ITEM_SCORE          = 1;
14 const int TARGET_SCORE        = 3;
15 const int FALLER_SCORE        = 10;
16 
17 
18 class GameItem
19 {
20   public:
21     enum ItemState { IdleState, NotAliveState, DyingState, FallingState, BornState,
22                      SelectedState };
23 
24     GameItem(quint8 id);
25     ~GameItem();
26 
id()27     inline quint8 id() const { return myId; }
setId(quint8 newid)28     inline void setId(quint8 newid) { myId = newid; }
29 
dx()30     inline int dx() const { return myXoff; }
dy()31     inline int dy() const { return myYoff; }
32 
opacity()33     inline qreal opacity() const { return myOpacity; }
setOpacity(qreal val)34     inline void setOpacity(qreal val) { myOpacity = val; }
35 
36     void advance();
37 
38     void idle();
isIdle()39     inline bool isIdle() const { return myState == IdleState; }
40 
41     void die();
isDying()42     inline bool isDying() const { return myState == DyingState; }
43 
44     void scheduleDeath();
isNotAlive()45     inline bool isNotAlive() const { return myState == NotAliveState; }
46 
47     void fall(int dx, int dy);
isFalling()48     inline bool isFalling() const { return myState == FallingState; }
49 
50     void born();
isBorning()51     inline bool isBorning() const { return myState == BornState; }
52 
53     void select();
isSelected()54     inline bool isSelected() const { return myState == SelectedState; }
55 
itemPixmap()56     inline const QPixmap& itemPixmap() const { return itemPixmap(myId); }
57     static const QPixmap& itemPixmap(int id);
58 
count(int id)59     static int count(int id) { return itemsCount[id]; }
dropCount()60     static void dropCount() { itemsCount.clear(); }
61 
62     void draw(QPainter &p, int x, int y);
63 
64   protected:
65 
66     quint8 myId;
67     ItemState myState;
68 
69     int myCount;
70 
71     int myXoff, myYoff;
72     int myDx, myDy;
73 
74     qreal myOpacity;
75 
76     static QMap<int,int> itemsCount;
77 };
78 
79 #endif // GAMEITEM_H
80