-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stages.hpp
367 lines (347 loc) · 9.27 KB
/
Stages.hpp
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// Stage Builder
void build_platforms() { // Platforms (+ Zapfish)
struct Platform ground = { 0, HEIGHT - 2 * BLOCK_SIZE, WIDTH / BLOCK_SIZE, REGULAR_PLATFORM, false, 0 }; // Ground always the same
stage.platforms[0] = ground;
int lastheight = HEIGHT - 2 * BLOCK_SIZE;
for (int i = 1; i < stage.totalplatforms; i++) {
int len;
int type;
int typerand;
switch (stage.num) {
case 1: // Wide regular platforms
len = random(5, 9);
type = 0;
break;
case 2: // Slightly slimmer
len = random(4, 8);
type = 0;
break;
case 3: // With red jump fish
len = random(4, 8);
type = 0;
break;
case 4: // With half ice platforms
len = random(4, 8);
type = random(2);
break;
case 5: // More ice
len = random(4, 8);
typerand = random(3);
if (typerand == 0) {
type = REGULAR_PLATFORM;
} else {
type = ICE_PLATFORM;
}
break;
case 6: // Jellies + red
len = random(4, 8);
typerand = random(2);
if (typerand == 0) {
type = REGULAR_PLATFORM;
} else {
type = JELLYFISH_PLATFORM;
}
break;
case 7: // Smaller jellies
len = random(4, 7);
typerand = random(2);
if (typerand == 0) {
type = REGULAR_PLATFORM;
} else {
type = JELLYFISH_PLATFORM;
}
break;
case 8: // Blue jellies + jellies + ice + regular
len = random(4, 7);
type = random(3);
break;
case 9: // Smaller
len = random(4, 6); // 3?
type = random(3);
break;
case 10: // Regular + starfish
len = random(4, 6);
type = REGULAR_PLATFORM;
break;
case 11: // Conveyors + reds
len = random(5, 7);
typerand = random(4);
if (typerand == 0) {
type = REGULAR_PLATFORM;
} else {
type = CONVEYOR_PLATFORM;
}
break;
case 12: // Same?
len = random(4, 7);
typerand = random(4);
if (typerand == 0) {
type = REGULAR_PLATFORM;
} else {
type = CONVEYOR_PLATFORM;
}
break;
case 13: // All platforms + starfish
len = random(4, 7);
typerand = random(4);
if (typerand == 3) {
type = 4;
} else {
type = typerand;
}
break;
case 14: // Reds + starfish + blue jellyfish
len = random(4, 7);
typerand = random(4);
if (typerand == 3) {
type = 4;
} else {
type = typerand;
}
break;
case 15: // Tiny platforms + starfish
len = random(2, 5);
typerand = random(4);
if (typerand == 3) {
type = 4;
} else {
type = typerand;
}
break;
case 16: // Small regulars + reds + starfish
len = random(2, 5);
type = REGULAR_PLATFORM;
break;
case 17: // Jellies + jellies + regulars + ice
len = random(2, 8);
typerand = random(4);
if (typerand == 3) {
type = 2;
} else {
type = typerand;
}
break;
case 18: // All (Faster 1.5x speed)
len = random(4, 7);
typerand = random(4);
if (typerand == 3) {
type = 4;
} else {
type = typerand;
}
break;
case 19: // Regular + ice + starfish
len = random(4, 7);
typerand = random(3);
if (typerand == 0) {
type = REGULAR_PLATFORM;
} else {
type = ICE_PLATFORM;
}
break;
case 20: // All thin
len = random(2, 5);
typerand = random(4);
if (typerand == 3) {
type = 4;
} else {
type = typerand;
}
break;
case 21: // All + starfish
len = random(3, 6);
typerand = random(4);
if (typerand == 3) {
type = 4;
} else {
type = typerand;
}
break;
case 22: // All platforms
len = random(3, 6);
typerand = random(4);
if (typerand == 3) {
type = 4;
} else {
type = typerand;
}
break;
case 23: // Thin + blues + reds
len = random(3, 6);
typerand = random(4);
if (typerand == 3) {
type = 4;
} else {
type = typerand;
}
break;
case 24: // Fast jellies + conveyors + starfish
len = random(4, 7);
typerand = random(2);
if (typerand == 0) {
type = JELLYFISH_PLATFORM;
} else {
type = CONVEYOR_PLATFORM;
}
break;
case 25: // Thin + fast + all + starfish + jellies
len = random(2, 5);
typerand = random(4);
if (typerand == 3) {
type = 4;
} else {
type = typerand;
}
break;
default:
len = random(5, 9);
type = 0;
break;
}
// Offset 2 and 3 in so that is possible to jump between opposite platforms
int xlow = (4 - len <= 0) ? 0 : 4 - len;
int xhigh = ((WIDTH / BLOCK_SIZE - 4 + len >= WIDTH / BLOCK_SIZE) ? WIDTH / BLOCK_SIZE : (WIDTH / BLOCK_SIZE - 4 + len)) - len + 1;
int x = random(xlow, xhigh) * BLOCK_SIZE;
int y = lastheight - random(5, 10) * BLOCK_SIZE;
bool facingright = (type == JELLYFISH_PLATFORM || type == CONVEYOR_PLATFORM) ? random(0, 2) : false;
byte sprite = 0;
stage.platforms[i] = { x, y, len, type, facingright, sprite };
lastheight = y;
}
zapfish = { lastheight - ZAP_UP - ZAP_SIZE };
}
void totalpowerups() {
if ((stage.num >= 3 && stage.num <= 13) || stage.num == 17 || stage.num == 19) {
stage.totalpowerups = random(1, 3);
} else if (stage.num == 14 || stage.num == 20) {
stage.totalpowerups = random(1, 4);
} else if ((stage.num >= 15 && stage.num <= 18) || stage.num == 21 || (stage.num >= 23 && stage.num <= 25)) {
stage.totalpowerups = random(3, 7);
} else {
stage.totalpowerups = 0;
}
// Cap just in case
if (stage.totalpowerups > MAX_POWERUPS) {
stage.totalpowerups = MAX_POWERUPS;
}
}
void build_powerups() { //Requires platforms to be built first
// Chooses space between platforms
for (int i = 0; i < stage.totalpowerups; i++) {
int aboveplatform = random(1, stage.totalplatforms - 1); // Won't choose the top or bottom one
int y = random(stage.platforms[aboveplatform + 1].y + BLOCK_SIZE, stage.platforms[aboveplatform].y - POWERUP_SIZE);
int x = random(WIDTH - POWERUP_SIZE);
byte type; // = random(3);
int randtype;
switch (stage.num) {
case 3:
type = POWERUP_FISH;
break;
case 4:
type = POWERUP_FISH;
break;
case 5:
type = POWERUP_FISH;
break;
case 6:
type = POWERUP_FISH;
break;
case 7:
type = POWERUP_FISH;
break;
case 8:
type = POWERUP_JELLY;
break;
case 9:
type = POWERUP_JELLY;
break;
case 10:
type = POWERUP_STAR;
break;
case 11:
type = POWERUP_FISH;
break;
case 12:
type = POWERUP_FISH;
break;
case 13:
type = POWERUP_STAR;
break;
case 14:
type = random(3);
break;
case 15:
type = POWERUP_STAR;
break;
case 16:
randtype = random(2);
if (randtype == 0) {
type = POWERUP_FISH;
} else {
type = POWERUP_STAR;
}
break;
case 17:
type = POWERUP_JELLY;
break;
case 18:
type = random(3);
break;
case 19:
type = POWERUP_STAR;
break;
case 20:
type = POWERUP_JELLY;
break;
case 21:
type = random(1, 3);
break;
case 23:
type = random(2);
break;
case 24:
type = random(3);
break;
case 25:
type = random(3);
break;
default:
type = 0;
break;
}
// Reroll overlapping powerups
bool nocollisions = true;
for (int k = 0; k < i; k++) {
if (x + POWERUP_SIZE >= stage.powerups[k].x && x <= stage.powerups[k].x + POWERUP_SIZE && y + POWERUP_SIZE >= stage.powerups[k].y && y <= stage.powerups[k].y + POWERUP_SIZE) {
nocollisions = false;
}
}
if (nocollisions) {
stage.powerups[i] = { x, y, type };
} else {
i--; // Reroll
}
}
}
void resetstage() { // Either decrease powerups, or increase len
if (stage.num > 25) {
stage.num = 25;
}
stage.staroffset = random(STAR_WRAP);
if (stage.num >= 18) {
stage.speed = 4;
} else if (stage.num >= 18) {
stage.speed = 3;
} else {
stage.speed = 2;
}
totalpowerups();
stage.totalplatforms = 22 + stage.totalpowerups - (stage.speed - 2); // Min 22 max 28
build_platforms();
build_powerups();
// Reset states
player = { (WIDTH - PLAYER_SIZE) / 2, HEIGHT - 2 * BLOCK_SIZE - PLAYER_SIZE, 0, 0, true, 0, 0, 0, 0, false, 1 };
camerapos = 0;
poisonheight = 128;
currentstagetimer = 0;
}