-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinesweeper.ino
739 lines (567 loc) · 17 KB
/
Minesweeper.ino
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/**
* -------------------------------------------------------------------------
* The famous Minesweeper game ported to the Gamebuino Meta
* -------------------------------------------------------------------------
* © 2025 Steph @ m1cr0lab
* https://gamebuino.m1cr0lab.com
* -------------------------------------------------------------------------
*/
#include <Gamebuino-Meta.h>
#include "src/sprites.h"
#include "src/sounds.h"
uint8_t const SCREEN_WIDTH = 160;
uint8_t const SCREEN_HEIGHT = 128;
uint8_t const CELL_SIZE = CELL_SPRITES[0];
uint8_t const BOARD_WIDTH = SCREEN_WIDTH / CELL_SIZE;
uint8_t const BOARD_HEIGHT = SCREEN_HEIGHT / CELL_SIZE;
uint8_t const EMOJI_SIZE = EMOJI_SPRITES[0];
uint8_t const SPLASH_WIDTH = SPLASH_TITLE[0];
uint8_t const SPLASH_HEIGHT = SPLASH_TITLE[1];
uint8_t const FONT_SIZE = 5;
uint8_t const SELECTOR_WIDTH = MENU_SELECTOR[0];
uint8_t const SELECTOR_HEIGHT = MENU_SELECTOR[1];
uint8_t const DIGIT_WIDTH = DIGIT_SPRITES[0];
uint8_t const DIGIT_HEIGHT = DIGIT_SPRITES[1];
uint8_t const LEVELS = 3;
uint8_t const BOMBS[LEVELS] = { 30, 50, 70 };
uint8_t const SAVING_BLOCK = 0;
uint16_t const WON_TIMEOUT_MS = 2000;
uint16_t const LOST_TIMEOUT_MS = 3000;
uint32_t const MAX_TIME_MS = 999000;
enum class GameState : uint8_t {
SPLASH,
LEVELS,
START,
PLAY,
TIME,
WIN,
WON,
LOST,
BEST_TIME
};
enum class Level : uint8_t { BEGINNER, INTERMEDIATE, EXPERT };
struct Cell {
bool mined;
bool exploded;
bool visited;
bool flagged;
uint8_t threats;
void reset() {
mined = false;
exploded = false;
visited = false;
flagged = false;
threats = 0;
}
};
struct Player {
uint8_t x;
uint8_t y;
};
Cell board[BOARD_HEIGHT][BOARD_WIDTH];
uint32_t best_time[LEVELS];
uint32_t start_time_ms;
uint32_t play_time_ms;
Player player;
Level level = Level::BEGINNER;
uint16_t visited_count;
uint16_t flagged_count;
GameState game_state = GameState::SPLASH;
Image sprites(CELL_SPRITES);
Image emoji(EMOJI_SPRITES);
Image splash(SPLASH_TITLE);
Image labels(LABEL_SPRITES);
Image selector(MENU_SELECTOR);
Image digits(DIGIT_SPRITES);
void load_best_time() {
bool const loaded = gb.save.get(SAVING_BLOCK, best_time, sizeof(best_time));
if (!loaded) {
for (uint8_t i = 0; i < 3; ++i) {
best_time[i] = MAX_TIME_MS;
}
}
}
void save_best_time() {
gb.save.set(SAVING_BLOCK, best_time, sizeof(best_time));
}
void reset_board() {
for (uint8_t i = 0; i < BOARD_HEIGHT; ++i) {
for (uint8_t j = 0; j < BOARD_WIDTH; ++j) {
board[i][j].reset();
}
}
}
void add_bomb(uint8_t const x, uint8_t const y) {
board[y][x].mined = true;
for (int8_t i = -1; i < 2; ++i) {
int const yi = y + i;
if (yi == -1 || yi == BOARD_HEIGHT) continue;
for (int8_t j = -1; j < 2; ++j) {
int const xj = x + j;
if (xj == -1 || xj == BOARD_WIDTH) continue;
if (xj == x && yi == y) continue;
Cell* const c = &board[yi][xj];
if (!c->mined) c->threats++;
}
}
}
void scatter_bombs() {
for (uint8_t i = 0; i < BOMBS[(uint8_t)level]; ++i) {
uint8_t x, y;
do {
x = random(BOARD_WIDTH);
y = random(BOARD_HEIGHT);
} while (board[y][x].mined);
add_bomb(x, y);
}
}
void start() {
reset_board();
scatter_bombs();
player.x = BOARD_WIDTH >> 1;
player.y = BOARD_HEIGHT >> 1;
visited_count = 0;
flagged_count = 0;
start_time_ms = millis();
game_state = GameState::PLAY;
}
void explore(uint8_t const x, uint8_t const y) {
for (int8_t i = -1; i < 2; ++i) {
int const yi = y + i;
if (yi == -1 || yi == BOARD_HEIGHT) continue;
for (int8_t j = -1; j < 2; ++j) {
int const xj = x + j;
if (xj == -1 || xj == BOARD_WIDTH) continue;
if (xj == x && yi == y) continue;
Cell* const c = &board[yi][xj];
if (c->visited || c->flagged) continue;
c->visited = true;
visited_count++;
if (!c->threats) {
explore(xj, yi);
}
}
}
}
void splash_screen() {
if (gb.buttons.pressed(BUTTON_A)) {
game_state = GameState::LEVELS;
gb.sound.fx(SFX_CONF_STATS);
}
}
void level_menu() {
if (gb.buttons.pressed(BUTTON_A)) {
game_state = GameState::START;
gb.sound.fx(SFX_START);
} else if (gb.buttons.pressed(BUTTON_B)) {
game_state = GameState::SPLASH;
gb.sound.fx(SFX_BACK);
} else if (gb.buttons.pressed(BUTTON_DOWN)) {
uint8_t level_index = (uint8_t)level;
++level_index %= LEVELS;
level = static_cast<Level>(level_index);
gb.sound.fx(SFX_TICK);
} else if (gb.buttons.pressed(BUTTON_UP)) {
uint8_t level_index = (uint8_t)level + LEVELS;
--level_index %= LEVELS;
level = static_cast<Level>(level_index);
gb.sound.fx(SFX_TICK);
}
}
bool has_won_the_game() {
return flagged_count + visited_count == BOARD_WIDTH * BOARD_HEIGHT;
}
void play() {
play_time_ms = millis();
if (play_time_ms - start_time_ms > MAX_TIME_MS) {
game_state = GameState::LOST;
return;
}
uint8_t const frames = 3;
if (gb.buttons.repeat(BUTTON_LEFT, frames) && player.x > 0) {
player.x--;
} else if (gb.buttons.repeat(BUTTON_RIGHT, frames) && player.x + 1 < BOARD_WIDTH) {
player.x++;
}
if (gb.buttons.repeat(BUTTON_UP, frames) && player.y > 0) {
player.y--;
} else if (gb.buttons.repeat(BUTTON_DOWN, frames) && player.y + 1 < BOARD_HEIGHT) {
player.y++;
}
Cell* const c = &board[player.y][player.x];
if (gb.buttons.pressed(BUTTON_A) && !c->visited && !c->flagged) {
if (c->mined) {
c->exploded = true;
game_state = GameState::LOST;
gb.sound.fx(SFX_EXPLODE);
} else {
c->visited = true;
visited_count++;
if (!c->threats) {
gb.sound.fx(SFX_EXPLORE);
explore(player.x, player.y);
} else {
gb.sound.fx(SFX_VISIT);
}
}
} else if (gb.buttons.pressed(BUTTON_B) && !c->visited && (c->flagged || flagged_count < BOMBS[(uint8_t)level])) {
c->flagged = !c->flagged;
flagged_count += c->flagged ? 1 : -1;
gb.sound.fx(SFX_FLAG);
} else if (gb.buttons.pressed(BUTTON_MENU)) {
game_state = GameState::TIME;
gb.sound.fx(SFX_CONF_STATS);
}
if (has_won_the_game()) {
game_state = GameState::WIN;
gb.sound.fx(SFX_WIN);
}
}
void show_time(bool ending = false) {
if (!ending) play_time_ms = millis();
bool const action = ending ? gb.buttons.pressed(BUTTON_MENU) || gb.buttons.pressed(BUTTON_A)
: gb.buttons.pressed(BUTTON_MENU) || gb.buttons.pressed(BUTTON_B);
if (action) {
if (ending) {
game_state = GameState::SPLASH;
gb.sound.fx(SFX_HOME);
} else {
game_state = GameState::PLAY;
gb.sound.fx(SFX_BACK);
}
}
}
void win() {
uint32_t const time = play_time_ms - start_time_ms;
if (time < best_time[(uint8_t)level]) {
best_time[(uint8_t)level] = time;
save_best_time();
}
game_state = GameState::WON;
}
void won() {
if (gb.buttons.pressed(BUTTON_MENU) || millis() - play_time_ms > WON_TIMEOUT_MS) {
game_state = GameState::BEST_TIME;
gb.sound.fx(SFX_CONF_STATS);
}
}
void lost() {
if (gb.buttons.pressed(BUTTON_MENU) || millis() - play_time_ms > LOST_TIMEOUT_MS) {
game_state = GameState::BEST_TIME;
gb.sound.fx(SFX_LOST);
}
}
void update() {
switch (game_state) {
case GameState::SPLASH: splash_screen(); break;
case GameState::LEVELS: level_menu(); break;
case GameState::START: start(); break;
case GameState::PLAY: play(); break;
case GameState::TIME: show_time(); break;
case GameState::WIN: win(); break;
case GameState::WON: won(); break;
case GameState::LOST: lost(); break;
case GameState::BEST_TIME: show_time(true); break;
default:;
}
}
uint8_t const SPLASH_BOARD_WIDTH = 14;
uint8_t const SPLASH_BOARD_HEIGHT = 7;
uint8_t const SPLASH_BOARD[7][14] = {
0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0xf, 0x0, 0x0, 0x0, 0x0, 0xf, 0xf,
0x0, 0x6, 0x6, 0x6, 0x7, 0x2, 0x0, 0x0, 0x0, 0x7, 0x6, 0x7, 0x0, 0xf,
0x0, 0x8, 0x6, 0x1, 0x6, 0x6, 0x7, 0x8, 0x2, 0x7, 0x1, 0x6, 0x6, 0x0,
0x0, 0x0, 0x7, 0x1, 0x1, 0x1, 0x1, 0x6, 0x6, 0x6, 0x1, 0x1, 0x6, 0x0,
0xf, 0x0, 0x8, 0x7, 0x6, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x7, 0x0,
0xf, 0xf, 0x0, 0x0, 0x7, 0x7, 0x6, 0x1, 0x1, 0x6, 0x6, 0x6, 0x7, 0x0,
0xf, 0xf, 0xf, 0xf, 0x0, 0x2, 0x6, 0x6, 0x1, 0x6, 0x2, 0x0, 0x0, 0xf
};
void draw_splash() {
uint8_t const h = SCREEN_HEIGHT >> 1;
uint8_t const xs = (SCREEN_WIDTH - SPLASH_WIDTH) >> 1;
uint8_t const ys = h - SPLASH_HEIGHT - 8;
uint8_t const xe = (SCREEN_WIDTH - EMOJI_SIZE) >> 1;
uint8_t const ye = ys - EMOJI_SIZE - 4;
gb.display.clear(ColorIndex::pink); // 0xe
emoji.setFrame(0);
gb.display.drawImage(xe, ye, emoji);
gb.display.drawImage(xs, ys, splash);
for (uint8_t i = 0; i < SPLASH_BOARD_HEIGHT; ++i) {
uint8_t const y = SCREEN_HEIGHT - SPLASH_BOARD_HEIGHT * CELL_SIZE + i * CELL_SIZE;
for (uint8_t j = 0; j < SPLASH_BOARD_WIDTH; ++j) {
uint8_t const x = ((SCREEN_WIDTH - SPLASH_BOARD_WIDTH * CELL_SIZE) >> 1) + j * CELL_SIZE;
uint8_t const c = SPLASH_BOARD[i][j];
if (c < 0xf) {
sprites.setFrame(c);
gb.display.drawImage(x, y, sprites);
}
}
}
}
void draw_levels() {
uint8_t const nb_labels = 4;
uint8_t max_w = 0;
for (uint8_t i = 0; i < nb_labels; ++i) {
uint8_t lw = LABEL_XYW[i * 3 + 2];
if (lw > max_w) max_w = lw;
}
uint8_t const h_margin = 6;
uint8_t const mx = (SCREEN_WIDTH - max_w) >> 1;
uint8_t const my = (SCREEN_HEIGHT - nb_labels * FONT_SIZE - (nb_labels - 1) * h_margin) >> 1;
uint8_t const sx = mx - SELECTOR_WIDTH - 4;
uint8_t const sy = my + (FONT_SIZE + h_margin) * (uint8_t)level;
gb.display.clear(ColorIndex::pink); // 0xe
gb.display.drawImage(sx, sy, selector);
gb.display.drawImage(
mx,
my - (h_margin << 1) - FONT_SIZE,
labels,
LABEL_XYW[0],
LABEL_XYW[1],
LABEL_XYW[2],
FONT_SIZE
);
for (uint8_t i = 1; i < 4; ++i) {
uint8_t const lx = LABEL_XYW[i * 3];
uint8_t const ly = LABEL_XYW[i * 3 + 1];
uint8_t const lw = LABEL_XYW[i * 3 + 2];
gb.display.drawImage(
mx,
my + (i - 1) * (FONT_SIZE + h_margin),
labels,
lx,
ly,
lw,
FONT_SIZE
);
}
}
uint8_t get_play_frame(Cell& c) {
uint8_t frame = 0;
if (c.visited) {
if (c.mined) frame = 3;
else if (c.threats) frame = 5 + c.threats;
else frame = 1;
} else if (c.flagged) {
frame = 2;
}
return frame;
}
uint8_t get_lost_frame(Cell& c) {
uint8_t frame = 0;
if (c.exploded) frame = 4;
else if (c.flagged) frame = c.mined ? 2 : 5;
else if (c.mined) frame = 3;
else if (c.visited) frame = c.threats ? 5 + c.threats : 1;
return frame;
}
uint8_t get_frame(Cell& c) {
switch (game_state) {
case GameState::PLAY:
case GameState::WIN:
case GameState::WON: return get_play_frame(c);
case GameState::LOST: return get_lost_frame(c);
}
}
void draw_board() {
gb.display.clear();
for (uint8_t i = 0; i < BOARD_HEIGHT; ++i) {
for (uint8_t j = 0; j < BOARD_WIDTH; ++j) {
sprites.setFrame(get_frame(board[i][j]));
gb.display.drawImage(j * CELL_SIZE, i * CELL_SIZE, sprites);
}
}
}
void draw_player() {
gb.display.setColor(0x4);
gb.display.drawRect(
player.x * CELL_SIZE - 1,
player.y * CELL_SIZE - 1,
CELL_SIZE + 2,
CELL_SIZE + 2
);
gb.display.drawRoundRect(
player.x * CELL_SIZE - 2,
player.y * CELL_SIZE - 2,
CELL_SIZE + 4,
CELL_SIZE + 4,
2
);
}
void draw_number(
uint16_t const n,
uint8_t const len,
uint8_t const x,
uint8_t const y,
uint8_t const margin = 1) {
char format[7];
char buffer[len + 1];
snprintf(format, 7, "%%0%uu", len);
snprintf(buffer, len + 1, format, n);
for (uint8_t i = 0; i < len; ++i) {
uint8_t const f = buffer[i] - 48;
digits.setFrame(f);
gb.display.drawImage(x + i * (margin + DIGIT_WIDTH), y, digits);
}
}
void draw_time(bool ending = false) {
uint8_t const bombs = BOMBS[(uint8_t)level] - flagged_count;
uint32_t const time = (play_time_ms - start_time_ms) / 1000;
uint8_t const boffset = 4 * 3;
uint8_t const bw = LABEL_XYW[boffset + 2];
uint8_t const bsw = DIGIT_WIDTH * 2 + 1;
uint8_t const mbw = max(bw, bsw);
uint8_t const toffset = boffset + 3;
uint8_t const tw = LABEL_XYW[toffset + 2];
uint8_t const tsw = DIGIT_WIDTH * 3 + 2;
uint8_t const mtw = max(tw, tsw);
uint8_t const h_margin = (SCREEN_WIDTH - mbw - mtw) / 3;
uint8_t const bx = h_margin + ((mbw - bw) >> 1);
uint8_t const bsx = h_margin + ((mbw - bsw) >> 1);
uint8_t const tx = (h_margin << 1) + mbw + ((mtw - tw) >> 1);
uint8_t const tsx = (h_margin << 1) + mbw + ((mtw - tsw) >> 1);
uint8_t yl = ending
? (SCREEN_HEIGHT - EMOJI_SIZE - ((FONT_SIZE + 6 + DIGIT_HEIGHT) << 1)) >> 2
: (SCREEN_HEIGHT - (FONT_SIZE + 6 + DIGIT_HEIGHT)) >> 1;
uint8_t yn = yl + FONT_SIZE + 6;
uint8_t const v_margin = ending ? yl : 0;
gb.display.clear(ColorIndex::pink); // 0xe
if (ending) {
emoji.setFrame(has_won_the_game() ? 1 : 2);
gb.display.drawImage((SCREEN_WIDTH - EMOJI_SIZE) >> 1, yl, emoji);
yl += EMOJI_SIZE + v_margin;
yn = yl + FONT_SIZE + 6;
}
gb.display.drawImage(
bx,
yl,
labels,
LABEL_XYW[boffset],
LABEL_XYW[boffset + 1],
bw,
FONT_SIZE
);
draw_number(bombs, 2, bsx, yn, 1);
gb.display.drawImage(
tx,
yl,
labels,
LABEL_XYW[toffset],
LABEL_XYW[toffset + 1],
tw,
FONT_SIZE
);
draw_number(time, 3, tsx, yn, 1);
if (ending) {
yl += FONT_SIZE + 6 + DIGIT_HEIGHT + v_margin;
yn = yl + FONT_SIZE + 6;
uint8_t const btoffset = toffset + 3;
uint8_t const btw = LABEL_XYW[btoffset + 2];
uint8_t const btsw = DIGIT_WIDTH * 3 + 2;
uint8_t const btx = (SCREEN_WIDTH - btw) >> 1;
uint8_t const btsx = (SCREEN_WIDTH - btsw) >> 1;
gb.display.drawImage(
btx,
yl,
labels,
LABEL_XYW[btoffset],
LABEL_XYW[btoffset + 1],
btw,
FONT_SIZE
);
draw_number(best_time[(uint8_t)level] / 1000, 3, btsx, yn, 1);
}
}
void draw() {
switch (game_state) {
case GameState::SPLASH: draw_splash(); break;
case GameState::START:
case GameState::LEVELS: draw_levels(); break;
case GameState::PLAY:
draw_board();
draw_player();
break;
case GameState::TIME: draw_time(); break;
case GameState::WIN:
case GameState::WON: draw_board(); break;
case GameState::LOST: draw_board(); break;
case GameState::BEST_TIME: draw_time(true); break;
default:;
}
}
float_t hue2rgb(float_t p, float_t q, float_t t) {
if (t < 0) t += 1.f;
if (t > 1) t -= 1.f;
if (t < 1.f / 6.f) return p + (q - p) * 6.f * t;
if (t < 1.f / 2.f) return q;
if (t < 2.f / 3.f) return p + (q - p) * 6.f * ((2.f / 3.f) - t);
return p;
}
uint16_t hsl2rgb(float_t h, float_t s, float_t l) {
float_t r, g, b;
if (s == 0) {
r = g = b = l;
} else {
float_t q = l < .5f ? l * (1 + s) : l + s - l * s;
float_t p = 2 * l - q;
r = hue2rgb(p, q, h + 1.f/3.f);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1.f/3.f);
}
uint8_t const red = r * 255.f;
uint8_t const green = g * 255.f;
uint8_t const blue = b * 255.f;
return (red >> 3) << 11 | (green >> 2) << 5 | blue >> 3;
}
void wave(uint32_t const ticks, uint16_t hue, uint8_t speed) {
uint8_t const t = (ticks << speed) & 0xff;
float_t const a = .02464f * t; // (2 * π / 255)
float_t const l = .25f * (1 + sin(a));
float_t const h = hue / 360.f;
for (uint8_t i = 0; i < 4; ++i) {
gb.lights._buffer[2*i] = gb.lights._buffer[2*i + 1] = hsl2rgb(h, 1.f, l);
}
}
void light_splash(uint32_t const ticks) {
for (uint8_t i = 0; i < 4; ++i) {
float_t const hue = (((ticks + i*5) << 3) % 360) / 360.f;
gb.lights._buffer[2*i] = gb.lights._buffer[2*i + 1] = hsl2rgb(hue, 1.f, .5f);
}
}
void light_time(uint32_t const ticks) {
wave(ticks, 240, 2);
}
void light_won(uint32_t const ticks) {
wave(ticks, 120, 5);
}
void light_lost(uint32_t const ticks) {
wave(ticks, 359, 6);
}
void light_best_time(uint32_t const ticks) {
wave(ticks, has_won_the_game() ? 140 : 40, 2);
}
void light() {
static uint32_t ticks = 0;
switch (game_state) {
case GameState::SPLASH: light_splash(ticks); break;
case GameState::TIME: light_time(ticks); break;
case GameState::WIN:
case GameState::WON: light_won(ticks); break;
case GameState::LOST: light_lost(ticks); break;
case GameState::BEST_TIME: light_best_time(ticks); break;
default: gb.lights.clear();
}
ticks++;
}
void setup() {
gb.begin();
gb.display.setPalette(PALETTE);
load_best_time();
gb.sound.fx(SFX_HOME);
}
void loop() {
gb.waitForUpdate();
update();
draw();
light();
}