-
Notifications
You must be signed in to change notification settings - Fork 3
/
game.c
609 lines (537 loc) · 25.7 KB
/
game.c
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
#include <gb/gb.h>
#include <gb/drawing.h>
#include <minesweeper.h>
#include <stdlib.h>
#include "game.h"
#include "graphics.h"
#include "utils.h"
#define GRID_WIDTH 20
#define GRID_HEIGHT 16
#define SCREEN_TILE_WIDTH 20
#define SCREEN_TILE_HEIGHT 18
#define MARKER_NB 0
TILESET(
game_tiles,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, // 0
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1C, 0x1C, 0x04, 0x04, 0x04, 0x04, // 1
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x1F, 0x1F,
0x00, 0x00, 0x3C, 0x3C, 0x04, 0x04, 0x04, 0x04, // 2
0x3C, 0x3C, 0x20, 0x20, 0x20, 0x20, 0x3C, 0x3C,
0x00, 0x00, 0x3C, 0x3C, 0x04, 0x04, 0x04, 0x04, // 3
0x3C, 0x3C, 0x04, 0x04, 0x04, 0x04, 0x3C, 0x3C,
0x00, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, // 4
0x3C, 0x3C, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x00, 0x00, 0x3C, 0x3C, 0x20, 0x20, 0x20, 0x20, // 5
0x3C, 0x3C, 0x04, 0x04, 0x04, 0x04, 0x3C, 0x3C,
0x00, 0x00, 0x3C, 0x3C, 0x20, 0x20, 0x20, 0x20, // 6
0x3C, 0x3C, 0x24, 0x24, 0x24, 0x24, 0x3C, 0x3C,
0x00, 0x00, 0x3C, 0x3C, 0x04, 0x04, 0x04, 0x04, // 7
0x0E, 0x0E, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x00, 0x00, 0x3C, 0x3C, 0x24, 0x24, 0x24, 0x24, // 8
0x3C, 0x3C, 0x24, 0x24, 0x24, 0x24, 0x3C, 0x3C,
0x00, 0x00, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x7E, // Unopened
0x00, 0x7E, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00,
0x00, 0x00, 0x08, 0x08, 0x18, 0x18, 0x38, 0x38, // Flagged
0x18, 0x18, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
0x18, 0x18, 0x24, 0x3C, 0x7E, 0x5A, 0xBD, 0xFF, // Mine
0xBD, 0xFF, 0x7E, 0x5A, 0x24, 0x3C, 0x18, 0x18,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Black
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // White
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
);
TILESET(
select_to_view_tiles,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC3, 0xC3, 0x81, 0x81, 0x89, 0x89,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x83, 0x83, 0x83, 0x83, 0x8F, 0x8F,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0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0x89, 0x89, 0x89,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2F, 0x2F, 0x28, 0x28, 0xA8, 0xA8, 0xA8, 0xA8, 0x6F, 0x6F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x48, 0x48, 0x48, 0x48, 0x40, 0x40, 0x30, 0x30,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0F, 0x0F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x43, 0x43,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x8C, 0x52, 0x52, 0x52, 0x52, 0x50, 0x50, 0xD0, 0xD0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x90, 0x90, 0x90, 0x90, 0x80, 0x80, 0x60, 0x60,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x74, 0x24, 0x24, 0x27, 0x27, 0x27, 0x27, 0x24, 0x24,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBC, 0xBC, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xBC, 0xBC,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x89, 0x89, 0x89, 0x89, 0x89, 0x89, 0x9D, 0x9D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x68, 0x68, 0x28, 0x28, 0x28, 0x28, 0x2F, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x08, 0x48, 0x48, 0x48, 0x48, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7A, 0x7A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x56, 0x56, 0x52, 0x52, 0x52, 0x52, 0x4C, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x10, 0x90, 0x90, 0x90, 0x90, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x74, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xBC, 0xBC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
);
TILEMAP(
footer_tilemap,
20,2,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27
);
TILESET(
double_row_digits_tileset,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1C, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x18, 0x18, 0x28, 0x28, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x24, 0x24, 0x24, 0x24, 0x04, 0x04, 0x08, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x24, 0x24, 0x04, 0x04, 0x04, 0x04, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x0C, 0x0C, 0x14, 0x14, 0x14, 0x14, 0x24, 0x24,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x3C, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x38, 0x38,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x10, 0x10, 0x20, 0x20, 0x38, 0x38, 0x24, 0x24,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x3C, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x38, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3C, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x10, 0x20, 0x20, 0x20, 0x20, 0x3C, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x04, 0x04, 0x04, 0x24, 0x24, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3C, 0x3C, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x04, 0x04, 0x04, 0x24, 0x24, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1C, 0x1C, 0x04, 0x04, 0x08, 0x08, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
);
TILESET(
start_footer_tileset,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE7, 0xE7, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0xE7, 0xE7,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0xA4, 0x24, 0x24, 0x34, 0x34, 0x34, 0x34, 0xAC, 0xAC,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x0F, 0x0F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4A, 0x4A, 0x4A, 0x4A, 0x6A, 0x6A, 0x69, 0x69, 0x59, 0x59,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x40, 0x40, 0x40, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFB, 0xFB, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA1, 0xA1, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x21,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7D, 0x7D, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x67, 0x91, 0x91, 0x91, 0x91, 0x81, 0x81, 0x61, 0x61,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD9, 0xD9, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x3D, 0x3D,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCF, 0xCF, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0xC2, 0xC2,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF2, 0xF2, 0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0x9E, 0x9E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xF0, 0xF0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x25, 0x25, 0x25, 0x25, 0x21, 0x21, 0x21, 0x21,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC9, 0xC9, 0x29, 0x29, 0x2F, 0x2F, 0x2F, 0x2F, 0xE9, 0xE9,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x78, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x78, 0x78,
0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x87, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x2C, 0x2C, 0x24, 0x24, 0x24, 0x24, 0xA4, 0xA4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x58, 0x58, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0x23, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x21, 0x21, 0x21, 0x21, 0x21, 0x21, 0xBD, 0xBD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x11, 0x11, 0x91, 0x91, 0x91, 0x91, 0x61, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x82, 0x82, 0x42, 0x42, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x2D, 0x2D, 0x25, 0x25, 0x25, 0x25, 0x19, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x78, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
);
TILEMAP(
start_footer_tilemap,
20, 2,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27
);
unsigned char sprites[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // Empty
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x81,0x81,0x81,0x81,0x81,0x81, // Marker
0x81,0x81,0xC1,0x81,0xA1,0xC1,0xFF,0xFF
};
// Offsets in game_tiles
enum tile {
Zero = 0,
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
Eight = 8,
Unopened = 9,
Flagged = 10,
Mine = 11,
Black = 12,
White = 13
};
// Digit to tile offset in game_tiles
uint8_t digit_to_tile(uint8_t digit)
{
return (uint8_t)digit; // Actually the same for now.
}
void move_marker(int16_t x, int16_t y)
{
move_sprite(MARKER_NB, (SCREENWIDTH / SCREEN_TILE_WIDTH) * (x+1), (SCREENHEIGHT / SCREEN_TILE_HEIGHT) * (y+2));
}
void show_marker()
{
set_sprite_tile(MARKER_NB, 1);
}
void hide_marker()
{
set_sprite_tile(MARKER_NB, 0);
}
struct loaded_tileset* loaded_game_tiles;
void set_tile(int16_t x, int16_t y, uint8_t tile)
{
place_tile(loaded_game_tiles, tile, x, y);
}
void show_double_row_digit(uint8_t digit, uint8_t x, uint8_t y)
{
struct loaded_tileset* digits = load_tileset(&double_row_digits_tileset);
place_tile(digits, digit, x, y);
place_tile(digits, 10 + digit, x, y + 1);
}
void show_mine_count(uint16_t mines)
{
show_double_row_digit((mines / 100) % 10, 4, SCREEN_TILE_HEIGHT-2);
show_double_row_digit((mines / 10) % 10, 5, SCREEN_TILE_HEIGHT-2);
show_double_row_digit(mines % 10, 6, SCREEN_TILE_HEIGHT-2);
}
void show_flag_count(uint16_t flags)
{
show_double_row_digit((flags / 100) % 10, 11, SCREEN_TILE_HEIGHT-2);
show_double_row_digit((flags / 10) % 10, 12, SCREEN_TILE_HEIGHT-2);
show_double_row_digit(flags % 10, 13, SCREEN_TILE_HEIGHT-2);
}
void show_time(uint16_t time)
{
show_double_row_digit((time / 100) % 10, 17, SCREEN_TILE_HEIGHT-2);
show_double_row_digit((time / 10) % 10, 18, SCREEN_TILE_HEIGHT-2);
show_double_row_digit(time % 10, 19, SCREEN_TILE_HEIGHT-2);
}
void show_won_game()
{
// Monotone bitmap where every element is row on screen.
// LSB is bottom of screen.
static const unsigned long bitmap[] = {
0x0000, 0x0000, 0x0F00, 0x30C0, 0x5020,
0x5220, 0xBB10, 0xBA90, 0x13A48, 0x11248,
0x11248, 0x13A48, 0xBA90, 0xBB10, 0x5220,
0x5020, 0x30C0, 0x0F00, 0x0000, 0x000
};
int16_t y, x;
for (y = 0;y < SCREEN_TILE_HEIGHT; y++)
{
for (x = 0;x < SCREEN_TILE_WIDTH;x++)
{
int8_t bit = (bitmap[x] >> ((SCREEN_TILE_HEIGHT - 1) - y)) & 1;
place_tile(loaded_game_tiles, bit ? White : Black, x, y);
}
delay(75);
}
}
void show_game_over()
{
// Monotone bitmap where every element is row on screen.
// LSB is bottom of screen.
static const uint32_t bitmap[] = {
0x0000, 0x7DF0, 0x4510, 0x5510, 0x5DF0,
0x0000, 0x3DE0, 0x4810, 0x3DE0, 0x0000,
0x7DF0, 0x4150, 0x3110, 0x4000, 0x7DF0,
0x0140, 0x7DB0, 0x5400, 0x45D0, 0x0000
};
int16_t sx = 0; // Spiral coordinates calculated from center
int16_t sy = 0;
int32_t i;
// Spiral.
for (i = 0; i < SCREEN_TILE_WIDTH*SCREEN_TILE_WIDTH; i++)
{
int16_t x = SCREEN_TILE_WIDTH / 2 + sx - 1;
int16_t y = SCREEN_TILE_HEIGHT / 2 + sy;
int8_t bit = (bitmap[x] >> ((SCREEN_TILE_HEIGHT-1)-y)) & 1;
set_tile(x,y, bit ? White : Black);
if (abs(sx) <= abs(sy) && (sx != sy || sx >= 0))
sx += ((sy >= 0) ? 1 : -1);
else
sy += ((sx >= 0) ? -1 : 1);
delay(5);
}
}
void load_tiles()
{
// Background tiles
loaded_game_tiles = load_tileset(&game_tiles);
// Sprite tiles
set_sprite_data(0, 2, sprites);
}
void show_select_to_view()
{
struct loaded_tileset* loaded_tileset = load_tileset(&select_to_view_tiles);
place_tiles(loaded_tileset, &select_to_view_map, 0, SCREEN_TILE_HEIGHT - select_to_view_map.height);
}
void render_start_footer()
{
place_tiles(load_tileset(&start_footer_tileset), &start_footer_tilemap, 0, SCREEN_TILE_HEIGHT-2);
}
void render_footer()
{
place_tiles(load_tileset(&footer_tileset), &footer_tilemap, 0, SCREEN_TILE_HEIGHT-2);
}
static uint16_t game_time;
// Called 16 times / second
void on_timer_overflow()
{
game_time++;
}
void start_timer()
{
disable_interrupts();
add_TIM(on_timer_overflow);
TAC_REG = 4; // Start timer at 4096 Hz
TIMA_REG = 0; // Reset timer
TMA_REG = 0; // Restart timer at 0 on overflow
game_time = 0;
enable_interrupts();
set_interrupts(TIM_IFLAG|VBL_IFLAG);
}
void stop_timer()
{
disable_interrupts();
remove_TIM(on_timer_overflow);
TAC_REG = 0;
enable_interrupts();
}
void render_tile(struct minesweeper_game* game, struct minesweeper_tile* tile, void* context)
{
uint8_t sprite;
unsigned x, y; minesweeper_get_tile_location(game, tile, &x, &y);
if (tile->has_mine && (tile->is_opened || game->state == MINESWEEPER_GAME_OVER))
sprite = Mine;
else if (tile->is_opened)
sprite = digit_to_tile(tile->adjacent_mine_count);
else if (tile->has_flag)
{
sprite = Flagged;
}
else
sprite = Unopened;
set_tile(x, y, sprite);
}
void render_all_tiles(struct minesweeper_game* game, bool mines_only)
{
struct minesweeper_tile *tile;
unsigned x, y;
for (x = 0;x < game->width;x++)
{
for (y = 0; y < game->height;y++)
{
tile = minesweeper_get_tile_at(game, x, y);
if (mines_only && !tile->has_mine)
continue;
render_tile(game, tile, NULL);
}
}
}
static unsigned char tilemap_buffer[SCREEN_TILE_WIDTH*SCREEN_TILE_HEIGHT];
static uint16_t display_time;
void update_hud(struct minesweeper_game* game)
{
show_flag_count(game->flag_count);
show_mine_count(game->mine_count);
show_time(display_time);
}
struct navigation
{
uint8_t button;
enum direction direction;
uint16_t hold; // Number of iterations in a row the button has been pressed
};
void handle_navigation(struct minesweeper_game* game, struct navigation* navigation)
{
if (button_pressed(navigation->button, 0))
{
// Immediately respond to first press, but then wait 8 iters before
// moving again if the button is not released
if (navigation->hold == 0 || navigation->hold > 8)
minesweeper_move_cursor(game, navigation->direction, true);
navigation->hold += 1;
}
else
{
navigation->hold = 0;
}
}
void play_game(int8_t difficulty)
{
struct navigation navigations[4] = {
{ .button = J_UP, .direction = UP, .hold = 0 },
{ .button = J_DOWN, .direction = DOWN, .hold = 0 },
{ .button = J_LEFT, .direction = LEFT, .hold = 0 },
{ .button = J_RIGHT, .direction = RIGHT, .hold = 0 }
};
unsigned x, y;
unsigned i;
struct minesweeper_game* game;
uint8_t *game_memory = malloc(minesweeper_minimum_buffer_size(GRID_WIDTH, GRID_HEIGHT));
game_time = 0;
display_time = 0;
game = minesweeper_init(GRID_WIDTH, GRID_HEIGHT, 0.1 * (difficulty+1), game_memory);
game->tile_update_callback = render_tile;
minesweeper_set_cursor(game, GRID_WIDTH / 2, GRID_HEIGHT / 2);
// Prepare graphics
load_tiles();
show_marker();
SHOW_BKG;
SHOW_SPRITES;
SPRITES_8x8;
update_hud(game);
render_start_footer();
render_all_tiles(game, false);
while (game->state != MINESWEEPER_GAME_OVER && game->state != MINESWEEPER_WIN)
{
disable_interrupts();
for (i = 0; i < sizeof(navigations) / sizeof(navigations[0]); i += 1)
handle_navigation(game, &navigations[i]);
if (button_pressed(J_A, -1))
{
if (game->state == MINESWEEPER_PENDING_START)
{
render_footer();
show_time(0);
start_timer();
}
minesweeper_open_tile(game, game->selected_tile);
update_hud(game);
}
if (button_pressed(J_B, -1))
{
minesweeper_toggle_flag(game, game->selected_tile);
update_hud(game);
}
minesweeper_get_tile_location(game, game->selected_tile, &x, &y);
move_marker(x, y);
if (display_time != game_time/16)
{
display_time = game_time/16;
update_hud(game);
}
enable_interrupts();
delay(50);
}
stop_timer();
hide_marker();
if (game->state == MINESWEEPER_GAME_OVER)
{
render_all_tiles(game, true);
}
// Save current tilemap
get_bkg_tiles(0, 0, SCREEN_TILE_WIDTH, SCREEN_TILE_HEIGHT, tilemap_buffer);
if (game->state == MINESWEEPER_WIN)
show_won_game();
else if (game->state == MINESWEEPER_GAME_OVER)
show_game_over();
// Add text to above screens
show_select_to_view();
while (1)
{
// While user presses select, temporarily show saved tilemap
if (button_pressed(J_SELECT, 0))
{
push_graphics();
set_bkg_tiles(0, 0, SCREEN_TILE_WIDTH, SCREEN_TILE_HEIGHT, tilemap_buffer);
while (button_pressed(J_SELECT, 0));
pop_graphics();
}
if (button_pressed(J_START, -1) || button_pressed(J_A, -1))
break;
}
free(game_memory);
}