-
Notifications
You must be signed in to change notification settings - Fork 7
/
PacMan.h
565 lines (533 loc) · 18.9 KB
/
PacMan.h
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
#define LEDMATRIX
#include "neomatrix_config.h"
#include <LEDSprites.h>
cLEDSprites Sprites(&ledmatrix);
#define MY_SPRITE_WIDTH 11
#define MY_SPRITE_HEIGHT 10
#define PACMAN_FRAMES 3
#define PINKY_FRAMES 2
#define max_x (MATRIX_WIDTH - MY_SPRITE_WIDTH - 1)
#define max_y (MATRIX_HEIGHT - MY_SPRITE_HEIGHT -1)
#define POWER_PILL_SIZE 4
const uint8_t PowerPillData[] =
{
B8_1BIT(01100000),
B8_1BIT(11110000),
B8_1BIT(11110000),
B8_1BIT(01100000)
};
const struct CRGB PowerPillColTab[] = { CRGB(48, 48, 255) };
const uint8_t PacmanRightData[] =
{
// Pacman Open
B8_2BIT(00021112),B8_2BIT(00000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(01111111),B8_2BIT(00000000),
B8_2BIT(21111110),B8_2BIT(00000000),
B8_2BIT(11111000),B8_2BIT(00000000),
B8_2BIT(11111000),B8_2BIT(00000000),
B8_2BIT(21111110),B8_2BIT(00000000),
B8_2BIT(01111111),B8_2BIT(00000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(00021112),B8_2BIT(00000000),
// Pacman Half
B8_2BIT(00021112),B8_2BIT(00000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(21111111),B8_2BIT(11200000),
B8_2BIT(11111200),B8_2BIT(00000000),
B8_2BIT(11111200),B8_2BIT(00000000),
B8_2BIT(21111111),B8_2BIT(11200000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(00021112),B8_2BIT(00000000),
// Pacman Closed
B8_2BIT(00021112),B8_2BIT(00000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(21111111),B8_2BIT(11200000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(21111111),B8_2BIT(11200000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(00021112),B8_2BIT(00000000)
};
const uint8_t PacmanRightMask[] =
{
// Pacman Open
B8_1BIT(00011111),B8_1BIT(00000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(01111111),B8_1BIT(00000000),
B8_1BIT(11111110),B8_1BIT(00000000),
B8_1BIT(11111000),B8_1BIT(00000000),
B8_1BIT(11111000),B8_1BIT(00000000),
B8_1BIT(11111110),B8_1BIT(00000000),
B8_1BIT(01111111),B8_1BIT(00000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(00011111),B8_1BIT(00000000),
// Pacman Half
B8_1BIT(00011111),B8_1BIT(00000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111100),B8_1BIT(00000000),
B8_1BIT(11111100),B8_1BIT(00000000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(00011111),B8_1BIT(00000000),
// Pacman Closed
B8_1BIT(00011111),B8_1BIT(00000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(00011111),B8_1BIT(00000000)
};
const struct CRGB PacmanRightColTab[] = { CRGB(255, 255, 0), CRGB(100, 100, 0), CRGB(255, 255, 255) };
const uint8_t PinkyData[] =
{
// Pinky Frame 1
B8_2BIT(00001110),B8_2BIT(00000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(01122212),B8_2BIT(22000000),
B8_2BIT(11122312),B8_2BIT(23100000),
B8_2BIT(11122212),B8_2BIT(22100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(11001110),B8_2BIT(01100000),
// Pinky Frame 2
B8_2BIT(00001110),B8_2BIT(00000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(01122212),B8_2BIT(22000000),
B8_2BIT(11122312),B8_2BIT(23100000),
B8_2BIT(11122212),B8_2BIT(22100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(10011011),B8_2BIT(00100000),
};
const uint8_t PinkyMask[] =
{
// Pinky Frame 1
B8_1BIT(00001110),B8_1BIT(00000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11001110),B8_1BIT(01100000),
// Pinky Frame 2
B8_1BIT(00001110),B8_1BIT(00000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(10011011),B8_1BIT(00100000),
};
const struct CRGB PinkyColTab[] = { CRGB(255, 0, 0), CRGB(255, 255, 255), CRGB(0, 0, 255) };
const uint8_t PacmanLeftData[] =
{
// Pacman Open
B8_2BIT(00021112),B8_2BIT(00000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(00011111),B8_2BIT(11000000),
B8_2BIT(00001111),B8_2BIT(11200000),
B8_2BIT(00000011),B8_2BIT(11100000),
B8_2BIT(00000011),B8_2BIT(11100000),
B8_2BIT(00001111),B8_2BIT(11200000),
B8_2BIT(00011111),B8_2BIT(11000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(00021112),B8_2BIT(00000000),
// Pacman Half
B8_2BIT(00021112),B8_2BIT(00000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(21111111),B8_2BIT(11200000),
B8_2BIT(00000211),B8_2BIT(11100000),
B8_2BIT(00000211),B8_2BIT(11100000),
B8_2BIT(21111111),B8_2BIT(11200000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(00021112),B8_2BIT(00000000),
// Pacman Closed
B8_2BIT(00021112),B8_2BIT(00000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(21111111),B8_2BIT(11200000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(21111111),B8_2BIT(11200000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(00021112),B8_2BIT(00000000)
};
const uint8_t PacmanLeftMask[] =
{
// Pacman Open
B8_1BIT(00011111),B8_1BIT(00000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(00011111),B8_1BIT(11000000),
B8_1BIT(00001111),B8_1BIT(11100000),
B8_1BIT(00000011),B8_1BIT(11100000),
B8_1BIT(00000011),B8_1BIT(11100000),
B8_1BIT(00001111),B8_1BIT(11100000),
B8_1BIT(00011111),B8_1BIT(11000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(00011111),B8_1BIT(00000000),
// Pacman Half
B8_1BIT(00011111),B8_1BIT(00000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(00000111),B8_1BIT(11100000),
B8_1BIT(00000111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(00011111),B8_1BIT(00000000),
// Pacman Closed
B8_1BIT(00011111),B8_1BIT(00000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(00011111),B8_1BIT(00000000)
};
const struct CRGB PacmanLeftColTab[] = { CRGB(255, 255, 0), CRGB(100, 100, 0), CRGB(255, 255, 255) };
const uint8_t GhostData[] =
{
// Ghost Frame 1
B8_2BIT(00001110),B8_2BIT(00000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(01122122),B8_2BIT(11000000),
B8_2BIT(11122122),B8_2BIT(11100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(11131313),B8_2BIT(11100000),
B8_2BIT(11313131),B8_2BIT(31100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(11001110),B8_2BIT(01100000),
// Ghost Frame 2
B8_2BIT(00001110),B8_2BIT(00000000),
B8_2BIT(00111111),B8_2BIT(10000000),
B8_2BIT(01111111),B8_2BIT(11000000),
B8_2BIT(01122122),B8_2BIT(11000000),
B8_2BIT(11122122),B8_2BIT(11100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(11131313),B8_2BIT(11100000),
B8_2BIT(11313131),B8_2BIT(31100000),
B8_2BIT(11111111),B8_2BIT(11100000),
B8_2BIT(10011011),B8_2BIT(00100000)
};
const uint8_t GhostMask[] =
{
// Ghost Frame 1
B8_1BIT(00001110),B8_1BIT(00000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11001110),B8_1BIT(01100000),
// Ghost Frame 2
B8_1BIT(00001110),B8_1BIT(00000000),
B8_1BIT(00111111),B8_1BIT(10000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(01111111),B8_1BIT(11000000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(11111111),B8_1BIT(11100000),
B8_1BIT(10011011),B8_1BIT(00100000)
};
const struct CRGB GhostColTab[] = { CRGB(0, 0, 255), CRGB(255, 255, 255), CRGB(255, 90, 120) };
const uint8_t S200Data[] =
{
B8_1BIT(00000000),B8_1BIT(00000000),
B8_1BIT(01000100),B8_1BIT(01000000),
B8_1BIT(10101010),B8_1BIT(10100000),
B8_1BIT(10101010),B8_1BIT(10100000),
B8_1BIT(00101010),B8_1BIT(10100000),
B8_1BIT(01001010),B8_1BIT(10100000),
B8_1BIT(11100100),B8_1BIT(01000000),
B8_1BIT(00000000),B8_1BIT(00000000),
B8_1BIT(00000000),B8_1BIT(00000000),
B8_1BIT(00000000),B8_1BIT(00000000)
};
const struct CRGB S200ColTab[] = { CRGB(0, 192, 255) };
const uint8_t EyesData[] =
{
B8_2BIT(00000000),B8_2BIT(00000000),
B8_2BIT(00000000),B8_2BIT(00000000),
B8_2BIT(01110001),B8_2BIT(11000000),
B8_2BIT(11111011),B8_2BIT(11100000),
B8_2BIT(11122011),B8_2BIT(12200000),
B8_2BIT(11122011),B8_2BIT(12200000),
B8_2BIT(01110001),B8_2BIT(11000000),
B8_2BIT(00000000),B8_2BIT(00000000),
B8_2BIT(00000000),B8_2BIT(00000000),
B8_2BIT(00000000),B8_2BIT(00000000)
};
const uint8_t EyesMask[] =
{
B8_1BIT(00000000),B8_1BIT(00000000),
B8_1BIT(00000000),B8_1BIT(00000000),
B8_1BIT(01110001),B8_1BIT(11000000),
B8_1BIT(11111011),B8_1BIT(11100000),
B8_1BIT(11111011),B8_1BIT(11100000),
B8_1BIT(11111011),B8_1BIT(11100000),
B8_1BIT(01110001),B8_1BIT(11000000),
B8_1BIT(00000000),B8_1BIT(00000000),
B8_1BIT(00000000),B8_1BIT(00000000),
B8_1BIT(00000000),B8_1BIT(00000000)
};
const struct CRGB EyesColTab[] = { CRGB(255, 255, 255), CRGB(0, 0, 255), CRGB(0, 0, 0) };
cSprite SprPacmanRight(MY_SPRITE_WIDTH, MY_SPRITE_HEIGHT, PacmanRightData, PACMAN_FRAMES, _2BIT, PacmanRightColTab, PacmanRightMask);
cSprite SprPinky(MY_SPRITE_WIDTH, MY_SPRITE_HEIGHT, PinkyData, PINKY_FRAMES, _2BIT, PinkyColTab, PinkyMask);
cSprite SprPacmanLeft(MY_SPRITE_WIDTH, MY_SPRITE_HEIGHT, PacmanLeftData, PACMAN_FRAMES, _2BIT, PacmanLeftColTab, PacmanLeftMask);
cSprite SprGhost(MY_SPRITE_WIDTH, MY_SPRITE_HEIGHT, GhostData, PINKY_FRAMES, _2BIT, GhostColTab, GhostMask);
cSprite SprPill(POWER_PILL_SIZE, POWER_PILL_SIZE, PowerPillData, 1, _1BIT, PowerPillColTab, PowerPillData);
cSprite Spr200(MY_SPRITE_WIDTH, MY_SPRITE_HEIGHT, S200Data, 1, _1BIT, S200ColTab, S200Data);
cSprite SprEyes(MY_SPRITE_WIDTH, MY_SPRITE_HEIGHT, EyesData, 1, _2BIT, EyesColTab, EyesMask);
static uint8_t inmaze = 0;
static uint8_t pinmaze = 0;
static uint8_t ginmaze = 0;
static bool ghostdead = false;
static uint8_t pacman_loops;
void pacman_setup(uint8_t loopcnt)
{
Serial.println("Sprite setup");
// Cleanup from previous run
Sprites.RemoveSprite(&SprPacmanLeft);
Sprites.RemoveSprite(&SprPacmanRight);
Sprites.RemoveSprite(&SprPinky);
Sprites.RemoveSprite(&SprGhost);
Sprites.RemoveSprite(&SprPill);
Sprites.RemoveSprite(&SprEyes);
Sprites.RemoveSprite(&Spr200);
// Rate is a divider, higher rate is slower.
SprPacmanRight.SetPositionFrameMotionOptions(0/*X*/, -10/*Y*/, 0/*Frame*/, 4/*FrameRate*/, 0/*XChange*/, 0/*XRate*/, 1/*YChange*/, 1/*YRate*/, SPRITE_DETECT_EDGE | SPRITE_DETECT_COLLISION);
Sprites.AddSprite(&SprPacmanRight);
SprPinky.SetPositionFrameMotionOptions( 0 /*X*/, -62/*Y*/, 0/*Frame*/, 2/*FrameRate*/, 0/*XChange*/, 0/*XRate*/, 1/*YChange*/, 1/*YRate*/, SPRITE_Y_KEEPIN | SPRITE_DETECT_EDGE);
Sprites.AddSprite(&SprPinky);
Serial.print("Top X for sprite: ");
Serial.print(max_x);
Serial.print(". Top Y for sprite: ");
Serial.println(max_y);
Serial.println("Sprite setup done");
inmaze = 0;
pinmaze = 0;
ginmaze = 0;
ghostdead = false;
pacman_loops = loopcnt;
}
uint8_t pacman_loop()
{
//uint8_t pcmr = SprPacmanRight.GetFlags();
int16_t pcmrx = SprPacmanRight.m_X;
int16_t pcmry = SprPacmanRight.m_Y;
int16_t pcmlx = SprPacmanLeft.m_X;
int16_t pcmly = SprPacmanLeft.m_Y;
int16_t gx = SprGhost.m_X;
int16_t gy = SprGhost.m_Y;
int16_t px = SprPinky.m_X;
int16_t py = SprPinky.m_Y;
//int8_t ex = SprEyes.m_X;
//int8_t ey = SprEyes.m_Y;
matrix->clear();
Sprites.UpdateSprites();
Sprites.DetectCollisions();
#if 0
Serial.print("rx: ");
Serial.print(pcmrx);
Serial.print(" ry: ");
Serial.print(pcmry);
Serial.print(" / ");
Serial.print("lx: ");
Serial.print(pcmlx);
Serial.print(" ly: ");
Serial.print(pcmly);
Serial.print(" / ");
Serial.print("px: ");
Serial.print(px);
Serial.print(" py: ");
Serial.print(py);
Serial.print(" | ");
Serial.print("gx: ");
Serial.print(gx);
Serial.print(" gy: ");
Serial.print(gy);
Serial.print(" / ");
Serial.print(pcmr & SPRITE_EDGE_X_MIN);
Serial.print(pcmr & SPRITE_EDGE_X_MAX);
Serial.print(pcmr & SPRITE_EDGE_Y_MIN);
Serial.print(pcmr & SPRITE_EDGE_Y_MAX);
Serial.print(" ");
Serial.print(pcmr, HEX);
Serial.print(" ");
Serial.println(inmaze);
#endif
// So you are going to ask "why are you not using the edge detection code"
// First, SPRITE_X|Y_KEEPIN does not work if you want your sprite to go around
// the screen like I'm doing
// Second, the edge detection is buggy-ish and triggered either right at the
// boundary or one pixel too late. That's not a big deal if you use it to
// bounce back, but it breaks things if you change direction at the edge, like
// I'm doing.
// On top of that, I have a small state machine to keep track of what kind
// of bouncing I'm doing depending on which time around it is, so there you go
// the code below is what I need...
// void SetMotion XRate, int8_t YChange, uint8_t YRate);
// Sets the X & Y change values and the rate of change. If the XRate and/or
// YRate is '0' then the appropriate axis motion will be disabled.
// The higher the rate, the more the sprite slows down
if (gy < 1 && ginmaze == 6) {
//Serial.println("Ghost hit bottom/left wall2");
SprGhost.SetMotion(1, 2, 0, 0);
ginmaze = 7;
}
else if (gx > max_x && ginmaze == 7) {
//Serialln("Ghost hit bottom/right wall2");
SprGhost.SetMotion(0, 0, 1, 2);
ginmaze = 8;
}
else if (gy > max_y && ginmaze == 8) {
SprGhost.SetMotion(-1, 2, 0, 0);
//Serialln("Ghost hit top/right wall2");
ginmaze = 9;
}
else if (gx < 1 && ginmaze == 9) {
//Serialln("Ghost hit top/left wall3");
SprGhost.SetMotion(0, 0, -1, 2);
ginmaze = 10;
}
if (pcmry >= max_y && !inmaze) inmaze = 1;
if (pcmry >= max_y && inmaze == 1) {
SprPacmanRight.SetMotion(1, 1, 0, 0);
//Serialln("Pacman hit top/left wall");
inmaze = 2;
}
else if (pcmrx >= max_x && inmaze == 2) {
//Serialln("Pacman hit top/right wall");
SprPacmanRight.SetMotion(0, 0, -1, 1);
inmaze = 3;
}
else if (pcmry <= 1 && inmaze == 3) {
//Serialln("Pacman hit bottom/right wall");
SprPacmanRight.SetMotion(-1, 1, 0, 0);
inmaze = 4;
if (pacman_loops == 0) {
SprPill.SetPositionFrameMotionOptions(3 /*X*/, MATRIX_HEIGHT - 7/*Y*/, 0/*Frame*/, 0/*FrameRate*/, 0/*XChange*/, 0/*XRate*/, 0/*YChange*/, 0/*YRate*/, 0);
Sprites.AddSprite(&SprPill);
} else { pacman_loops--; }
}
else if (pcmrx <= 1 && inmaze == 4) {
//Serialln("Pacman hit bottom/left wall");
SprPacmanRight.SetMotion(0, 0, 1, 1);
inmaze = 1;
}
if (inmaze<6 && SprPacmanRight.GetFlags() & SPRITE_COLLISION)
{
//Serialln("Pill Collision");
inmaze = 6;
ginmaze = 6;
Sprites.RemoveSprite(&SprPinky);
Sprites.RemoveSprite(&SprPacmanRight);
Sprites.RemoveSprite(&SprPill);
SprPacmanLeft.SetPositionFrameMotionOptions(SprPacmanRight.m_X, SprPacmanRight.m_Y, 0/*Frame*/, 4/*FrameRate*/, 0/*XChange*/, 0/*XRate*/, -1/*YChange*/, 1/*YRate*/, SPRITE_DETECT_EDGE | SPRITE_DETECT_COLLISION);
Sprites.AddSprite(&SprPacmanLeft);
SprGhost.SetPositionFrameMotionOptions(SprPinky.m_X, SprPinky.m_Y, 0/*Frame*/, 3/*FrameRate*/, 0/*XChange*/, 2/*XRate*/, -1/*YChange*/, 2/*YRate*/, SPRITE_DETECT_EDGE | SPRITE_DETECT_COLLISION);
Sprites.AddSprite(&SprGhost);
}
else if (pcmly <= 1 && inmaze == 6) {
//Serialln("Pacman hit bottom/left wall2");
SprPacmanLeft.SetMotion(1, 1, 0, 0);
inmaze = 7;
}
else if (pcmlx >= max_x && inmaze == 7) {
//Serialln("Pacman hit bottom/right wall2");
SprPacmanLeft.SetMotion(0, 0, 1, 1);
inmaze = 8;
}
else if (pcmly >= max_y && inmaze == 8) {
SprPacmanLeft.SetMotion(-1, 1, 0, 0);
//Serialln("Pacman hit top/right wall2");
inmaze = 9;
}
else if (pcmlx <= 1 && inmaze == 9) {
//Serialln("Pacman hit top/left wall3");
SprPacmanLeft.SetMotion(0, 0, -1, 1);
inmaze = 10;
}
if (py >= max_y && !pinmaze) pinmaze = 1;
if (py >= max_y && pinmaze == 1) {
SprPinky.SetMotion(1, 1, 0, 0);
//Serialln("Pinky hit top/left wall");
pinmaze = 2;
}
else if (px >= max_x && pinmaze == 2) {
//Serialln("Pinky hit top/right wall");
SprPinky.SetMotion(0, 0, -1, 1);
pinmaze = 3;
}
else if (py <= 1 && pinmaze == 3) {
//Serialln("Pinky hit bottom/right wall");
SprPinky.SetMotion(-1, 1, 0, 0);
pinmaze = 4;
}
else if (px <= 1 && pinmaze == 4) {
//Serialln("Pinky hit bottom/left wall");
SprPinky.SetMotion(0, 0, 1, 1);
pinmaze = 1;
}
// ginmaze > 5 &&
if (!ghostdead && SprGhost.GetFlags() & SPRITE_COLLISION)
{
//Serialln("Ghost killed");
Sprites.RemoveSprite(&SprGhost);
Spr200.SetPositionFrameMotionOptions(SprGhost.m_X+1, SprGhost.m_Y, 0, 0, 0, 0, 0, 0);
Sprites.AddSprite(&Spr200);
ghostdead = true;
SprEyes.SetPositionFrameMotionOptions(SprGhost.m_X, SprGhost.m_Y, 0, 0, 0, 0, -1, 3, 0);
Sprites.AddSprite(&SprEyes);
}
if (ghostdead && SprEyes.m_Y < 1) {
//Serialln("Eye Bounce #1");
SprEyes.m_Y = 1;
SprEyes.SetMotion(0, 0, 1, 3);
}
else if (SprEyes.m_Y > MATRIX_HEIGHT) {
//Serialln("Ghost eyes left the building, stopping");
SprEyes.m_Y = 0;
return 0;
}
Sprites.RenderSprites();
ledmatrix.DrawLine (ledmatrix.Width()/2, MY_SPRITE_HEIGHT, ledmatrix.Width()/2, ledmatrix.Height() - 1 - MY_SPRITE_HEIGHT, CRGB::Grey);
matrix->show();
return 1;
}
// vim:sts=4:sw=4