-
Notifications
You must be signed in to change notification settings - Fork 1
/
gamebonus.h
115 lines (76 loc) · 2.29 KB
/
gamebonus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef GAMEBONUS_H
#define GAMEBONUS_H
#include <QPixmap>
#include <QString>
#define BONUS_FOR_SECOND 2
#define ITEM_SCORE 1
#define TARGET_SCORE 3
class GameScene;
struct PlayerInfo;
struct LevelPackInfo;
struct ItemBonusInfo
{
ItemBonusInfo() :
levelCount(0), totalCount(0), count(0)
{
}
inline void addScore(int score)
{
levelCount += score;
totalCount += score;
count += score;
}
inline void spendScore(int score)
{
count -= score;
}
int levelCount, totalCount, count;
};
struct BonusInfo
{
BonusInfo(const QRect &rect, int score = 0,
const QString &resource = "",
const QString &name = "", const QString &comment = "");
BonusInfo(const QRect &rect, int score, const QPixmap &pixmap, const QString &name, const QString &comment);
BonusInfo(int score, const QPixmap &pixmap, const QString &name, const QString &comment);
BonusInfo(const QString &name, const QString &comment);
void initFrom(BonusInfo *source);
inline bool isEmpty() const { return !score; }
inline void setEmpty() { score = 0; }
QRect rect;
QPixmap pixmap;
int score;
QString name, comment;
};
class GameBonus : public QObject
{
Q_OBJECT
public:
GameBonus();
void setupItems(int count);
void readProfile(LevelPackInfo *lpi, GameScene *scene);
void writeProfile(LevelPackInfo *lpi);
void initGraphics(GameScene *scene);
void addItemScore(int id, int score) { items[id].addScore(score); }
inline bool isActive() const { return bonusId >= 0; }
int collectedOnLevel() const;
int collectedTotal() const;
void drawBonusMenu(GameScene *scene, QPainter &p);
void showBonusMenu(GameScene *scene, int idx);
void hideBonusMenu(GameScene *scene);
void updateItems(GameScene *scene, QPainter &p);
void checkMouseActions(GameScene *scene, const QPoint &pos);
bool checkMouseHover(const QPoint &pos);
private:
void drawBonusInfo(GameScene *scene, QPainter &p, BonusInfo *info, int idx);
void activateBonus(GameScene *scene, BonusInfo *info, int idx);
void updateRects(int cnt);
int bonusId;
QList<QRect> bonusRects;
QList<BonusInfo*> bonusInfo;
QList<ItemBonusInfo> items;
int diff;
bool puzzle;
};
extern GameBonus * gameBonus;
#endif // GAMEBONUS_H