forked from harmattan/brainparty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbpsays.cpp
318 lines (249 loc) · 8.38 KB
/
bpsays.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// Brain Party
// Copyright (C) 2010 Paul Hudson (http://www.tuxradar.com/brainparty)
// Brain Party is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "bpsays.h"
#include "Minigame.h"
BPMiniGame_BPSays::BPMiniGame_BPSays(BPGame* game) : BPMiniGame(game) {
sfcBackground = TheGame->LoadBitmap("bpsays", 320, 480);
sfcBackgroundChoosing = TheGame->LoadBitmap("bpsays_choosing", 320, 480);
sfcCircle = TheGame->LoadBitmap("white_circle", 64, 64);
Sequence = new BPList<int>();
Numbers = new BPPList<Texture*>();
Speed = NumCorrect = NumErrors = SequenceCounter = SelectedNumber = NumTries = TimeStarted = 0;
Countdown = -1;
Repeating = false;
GameTitle = "Brain Party Says";
GameHelp = "Watch the colours I'll show you, then copy the sequence yourself. I'll make things harder by showing you words that are intentionally wrong - ignore those words and focus on the colours you see!";
GameHelp2 = "The key in this game is to focus on the colours, not the words. That is, Brain Party might show a colour like Red, but then show the text \"Blue\" to try to put you off. You need to ignore the text and look at the colour: the correct answer is Red, not Blue.";
MiniGameType = PUZZLE;
Numbers->Add(TheGame->LoadBitmap("1", 215, 215));
Numbers->Add(TheGame->LoadBitmap("2", 215, 215));
Numbers->Add(TheGame->LoadBitmap("3", 215, 215));
ColourList.Add(Colour(0.0f, 0.0f, 1.0f, 1.0f));
ColourList.Add(Colour(0.0f, 1.0f, 0.0f, 1.0f));
ColourList.Add(Colour(1.0f, 0.75f, 0.0f, 1.0f));
ColourList.Add(Colour(1.0f, 0.0f, 0.0f, 1.0f));
SpriteFont* tex = NULL; TheGame->AllocString(&tex, "Blue", ALMOSTEPIC, 320, 297, CENTRED, true);
ColourWords.Add(tex);
SpriteFont* tex2 = NULL; TheGame->AllocString(&tex2, "Green", ALMOSTEPIC, 320, 297, CENTRED, true);
ColourWords.Add(tex2);
SpriteFont* tex3 = NULL; TheGame->AllocString(&tex3, "Yellow", ALMOSTEPIC, 320, 297, CENTRED, true);
ColourWords.Add(tex3);
SpriteFont* tex4 = NULL; TheGame->AllocString(&tex4, "Red", ALMOSTEPIC, 320, 297, CENTRED, true);
ColourWords.Add(tex4);
GameState = 2;
Speed = 700;
}
BPMiniGame_BPSays::~BPMiniGame_BPSays() {
SAFE_DELETE(sfcBackground);
SAFE_DELETE(sfcBackgroundChoosing);
SAFE_DELETE(sfcCircle);
ColourWords.Clear();
Sequence->Clear();
SAFE_DELETE(Sequence);
Numbers->Clear();
SAFE_DELETE(Numbers);
}
void BPMiniGame_BPSays::Start() {
Countdown = TheGame->TickCount;
TimeStarted = TheGame->TickCount;
TheGame->PlaySound("beep_hi");
}
int BPMiniGame_BPSays::GetWeight() {
float TimePassed = (TheGame->TickCount - TimeStarted) / 1000.0f;
return MinMax(570 - (NumErrors * 50) - (TimePassed / 0.9));
}
void BPMiniGame_BPSays::Render() {
if (Countdown == -1) return; // don't do anything until the game begins!
switch (GameState) {
case 0:
case 1:
case 2:
// counting down
TheGame->DrawImage(sfcBackground, 0, 0);
{
float diff = (Countdown + Speed) - TheGame->TickCount;
diff /= Speed;
diff = TheGame->Clamp(diff, 0.0f, 1.0f);
Colour fade = Colour(1.0f, 1.0f, 1.0f, diff);
TheGame->DrawImage((*Numbers)[GameState], MiniGameHalfWidth - 107, MiniGameHalfHeight - 107, fade);
}
if (Countdown + Speed < TheGame->TickCount) {
--GameState;
Countdown = TheGame->TickCount;
if (GameState == -1) {
GameState = 4;
// if we're repeating, don't add to the sequence
if (Repeating) {
Repeating = false;
} else {
GenerateSequence();
}
} else {
TheGame->PlaySound("beep_hi");
}
}
break;
case 4:
// showing a sequence
TheGame->FillRectangle(ColourList[(*Sequence)[SequenceCounter]], 0, 0, 320, 480);
if (SequenceCounter % 2 == 0) {
TheGame->DrawString(ColourWords[(SequenceCounter + Sequence->Count) % ColourWords.Count], WHITE, 0, 0);
TheGame->DrawString(ColourWords[(SequenceCounter + Sequence->Count) % ColourWords.Count], WHITE, 0, 200);
} else {
TheGame->DrawString(ColourWords[(SequenceCounter + Sequence->Count) % ColourWords.Count], WHITE, 0, 100);
TheGame->DrawString(ColourWords[(SequenceCounter + Sequence->Count) % ColourWords.Count], WHITE, 0, 300);
}
if (Countdown + Speed < TheGame->TickCount) {
++SequenceCounter;
Countdown = TheGame->TickCount;
}
if (SequenceCounter == Sequence->Count) {
GameState = 5;
SequenceCounter = 0;
SelectedNumber = -1;
}
break;
case 5:
// players copying the sequence
TheGame->DrawImage(sfcBackgroundChoosing, 0, 0);
{
Colour col = Colour(1.0f, 1.0f, 1.0f, 0.6f);
switch (SelectedNumber) {
case 0:
TheGame->DrawImage(sfcCircle, 128, 292, col);
break;
case 1:
TheGame->DrawImage(sfcCircle, 35, 200, col);
break;
case 2:
TheGame->DrawImage(sfcCircle, 221, 200, col);
break;
case 3:
TheGame->DrawImage(sfcCircle, 128, 106, col);
break;
}
}
break;
case 6:
// player made a mistake; show the oops message then repeat the sequence
Repeating = true;
TheGame->DrawImage(sfcBackground, 0, 0);
RenderWrong();
if (Countdown + Speed < TheGame->TickCount) {
SequenceCounter = 0;
GameState = 2;
Countdown = TheGame->TickCount;
TheGame->PlaySound("beep_hi");
}
break;
case 7:
// player was correct; show the correct message then continue
TheGame->DrawImage(sfcBackgroundChoosing, 0, 0);
{
Colour col = Colour(1.0f, 1.0f, 1.0f, 0.6f);
switch (SelectedNumber) {
case 0:
TheGame->DrawImage(sfcCircle, 128, 292, col);
break;
case 1:
TheGame->DrawImage(sfcCircle, 35, 200, col);
break;
case 2:
TheGame->DrawImage(sfcCircle, 221, 200, col);
break;
case 3:
TheGame->DrawImage(sfcCircle, 128, 106, col);
break;
}
}
RenderCorrect();
if (Countdown + Speed < TheGame->TickCount) {
GameState = 2;
TheGame->PlaySound("beep_hi");
SelectedNumber = -1;
Countdown = TheGame->TickCount;
}
break;
}
}
void BPMiniGame_BPSays::GenerateSequence() {
SequenceCounter = 0;
if (NumCorrect == 0) {
Sequence->Add(TheGame->RandomRange(0, ColourList.Count - 1));
} else {
// don't repeat the same colour twice in a row
// otherwise it's hard to spot!
Sequence->Add(TheGame->RandomRangeExcept(0, ColourList.Count - 1, (*Sequence)[Sequence->Count - 1]));
}
}
void BPMiniGame_BPSays::Tick() {
if (NumTries >= 8 && !MarathonMode) {
Success();
}
}
void BPMiniGame_BPSays::OnMouseDown() {
}
void BPMiniGame_BPSays::OnMouseMove() {
}
void BPMiniGame_BPSays::OnMouseUp() {
if (GameState != 5) {
// player is copying the sequence
return;
}
BPPoint blue = BPPoint(159, 374);
BPPoint green = BPPoint(16, 232);
BPPoint yellow = BPPoint(302, 232);
BPPoint red = BPPoint(159, 88);
SelectedNumber = 0;
float distance = BPPoint::Distance(TouchEvent, blue);
if (BPPoint::Distance(TouchEvent, green) < distance) {
distance = BPPoint::Distance(TouchEvent, green);
SelectedNumber = 1;
}
if (BPPoint::Distance(TouchEvent, yellow) < distance) {
distance = BPPoint::Distance(TouchEvent, yellow);
SelectedNumber = 2;
}
if (BPPoint::Distance(TouchEvent, red) < distance) {
distance = BPPoint::Distance(TouchEvent, red);
SelectedNumber = 3;
}
if ((*Sequence)[SequenceCounter] == SelectedNumber) {
++SequenceCounter;
TheGame->PlaySound("gem_select");
} else {
Wrong();
}
if (SequenceCounter == Sequence->Count) {
LevelUp();
}
}
void BPMiniGame_BPSays::LevelUp() {
++NumTries;
GameState = 7;
++NumCorrect;
Speed -= 25;
Countdown = TheGame->TickCount;
}
void BPMiniGame_BPSays::Wrong() {
++NumTries;
TheGame->PlaySound("wrong");
SelectedNumber = -1;
GameState = 6;
Countdown = TheGame->TickCount;
++NumErrors;
}
void BPMiniGame_BPSays::SetMarathon() {
MarathonMode = true;
}