-
Notifications
You must be signed in to change notification settings - Fork 1
/
gamestatics.cpp
243 lines (194 loc) · 5.41 KB
/
gamestatics.cpp
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include "scene_if.h"
#include "baseitem.h"
#include "gamestock.h"
#include "gamesound.h"
#include "gamebonus.h"
#include "gametools.h"
#include <QApplication>
IScene::IScene() :
time(0),
bonus(0), bonus_time(0),
targets(0),
max_level(0)
{
scene = this;
}
IScene * scene = 0;
////////////////////////////////////////////////////////////////////////////////
void IScene::createScorePopup(int x, int y, int score)
{
createStaticPopup(QRect(x,y,X56,Y56),
QString::number(score),
Qt::AlignCenter,
gameStock->Font12,
Qt::white,
1,
0, 20,
0, -1);
}
void IScene::createPixmapPopup(int x, int y, int dx, int dy, const QPixmap &pm, int steps)
{
PixmapItem *bi = new PixmapItem(x,y,dx,dy,pm,steps);
tempItems.append(bi);
}
void IScene::createStaticPopup(QRect rect, const QString &text, int textFlags,
const QFont &font, QColor color,
qreal opacity, int staysteps, int steps,
int dx, int dy)
{
TextItem *ti = new TextItem(rect,
text,
textFlags,
font,
color,
opacity,
staysteps,
steps,
dx, dy);
tempItems.append(ti);
}
////////////////////////////////////////////////////////////////////////////////
void IScene::removeBlock(PlaceInfo &pi, int row, int col)
{
bool b1 = true;
if (pi.place & Block2)
{
b1 = false;
pi.place = (pi.place & ~Block2) | Block1;
}
else
{
pi.place = (pi.place & ~Block1);
}
sndEngine->playSound(GameSound::sndUnblock);
// create ghost
createPixmapPopup(col2x(col), row2y(row), (qrand() % 3)-1, 10 + (qrand() % 5)-2,
block1,
50);
}
void IScene::removeTarget(PlaceInfo &pi, int row, int col)
{
bool t1 = true;
if (pi.place & Target2)
{
t1 = false;
pi.place = (pi.place & ~Target2) | Target1;
}
else
pi.place = (pi.place & ~Target1);
// sndEngine->playSound(GameSound::sndTarget);
// create ghost
createPixmapPopup(col2x(col), row2y(row), (qrand() % 3)-1, 10 + (qrand() % 5)-2,
t1 ? target1: target2,
50);
// // update bonus
// bonus++;
// bonus_time = 10 + gameBonus->bonusSpeed();
// bonusTimer->start();
}
void IScene::removeAndCountItem(int row, int col)
{
PlaceInfo &pi = data(row,col);
// it was already scheduled and counted
if (pi.isProcessed())
return;
pi.setProcessed();
bool remove = true;
int upscore = 0;
if (pi.hasBlock())
{
remove = false;
removeBlock(pi, row, col);
}
else
if (pi.hasTarget())
{
targets--;
// score for target
upscore = TARGET_SCORE + toolset->bonusScore();
removeTarget(pi, row, col);
}
else
if (!pi.item->isNotAlive()) // do not count again
{
upscore = ITEM_SCORE; // + toolset->bonusScore();
}
if (upscore)
{
// increase score
upscore *= bonus;
score += upscore;
toolset->addScore(upscore);
// add score popup
createScorePopup(col2x(col), row2y(row), upscore);
}
if (remove && !pi.item->isNotAlive()) // do not remove again
{
gameBonus->addItemScore(pi.item->id(), ITEM_SCORE);
pi.item->scheduleDeath();
}
}
void IScene::removeAndCountItemOnly(int row, int col)
{
PlaceInfo &pi = data(row,col);
// it was already scheduled and counted
if (pi.isProcessed())
return;
pi.setProcessed();
if (!pi.item->isNotAlive()) // do not count again
{
// increase score
int upscore = ITEM_SCORE; // + toolset->bonusScore();
score += upscore;
toolset->addScore(upscore);
// add score popup
createScorePopup(col2x(col), row2y(row), upscore);
gameBonus->addItemScore(pi.item->id(), ITEM_SCORE);
pi.item->scheduleDeath();
}
}
////////////////////////////////////////////////////////////////////////////////
void IScene::addTime(int timeAdd)
{
time += timeAdd;
createStaticPopup(QRect(DX(975), DY(75), DX(100), DY(30)),
QString("+%1").arg(timeAdd),
Qt::AlignLeft | Qt::AlignTop,
gameStock->Font20,
Qt::yellow,
1,
0, 20,
0, -1
);
}
////////////////////////////////////////////////////////////////////////////////
void IScene::setDefaultGameCursor()
{
QApplication::setOverrideCursor(gameStock->GameCursor);
}
void IScene::restoreCursor()
{
lastCursor = QApplication::overrideCursor() ? (* QApplication::overrideCursor()) : QCursor();
while (QApplication::overrideCursor())
QApplication::restoreOverrideCursor();
setDefaultGameCursor();
}
////////////////////////////////////////////////////////////////////////////////
void IScene::drawTransRect(QPainter &p, const QRect &r, QColor borderColor, QColor bgColor, qreal op)
{
p.setOpacity(op);
p.setPen(QPen(borderColor, 2));
p.setBrush(bgColor);
#if QT_VERSION >= 0x040400
p.drawRoundedRect(r, 5,5);
#else
p.drawRect(r);
#endif
}
void IScene::drawTextHint(QPainter &p)
{
p.setOpacity(1);
p.setPen(QPen(Qt::white));
p.setFont(gameStock->Font12);
p.drawText(0,DY(690),DX(860),DY(30), Qt::AlignRight, hintText);
}