-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfb_question.c
1139 lines (958 loc) · 28 KB
/
fb_question.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
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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* mehPL:
* This is Open Source, but NOT GPL. I call it mehPL.
* I'm not too fond of long licenses at the top of the file.
* Please see the bottom.
* Enjoy!
*/
// DUH! It's called "Power-Ups"
//fb_question is the good-ol' "Mario" Question-box, using a frameBuffer...
// It was created after seg_question, which was created after a
// frameBuffer-based method. Long convoluted story.
// Essentially, fb_question is the latest (a/o v66) version of the
// Mario-Question-Box, which has actually been installed at a somewhat
// permanent location for public-interaction. (and Seg_question has since
// been put on the back-burner).
// When the question-box is "hit" it displays a random sprite:
// A Coin, 1-up, Biggie, Star, Flower, or possibly a Goomba
// If you *hit* the goomba, it dies.
// As-implemented (in main), the ADC is used as the hit-detector. Connected
// to it is a piezo-element. Unfortunately, I'm certain, the
// threshold-values, etc. for this "hit-sensor" will have to be configured
// for your particular hardware... And, in fact, I've found that it's
// sensitive to electrical noise (e.g. from the backlight inverter) as well
// as things like temperature. It's kinda hokey, but it's also in main()
// and could easily be converted to a simple momentary-switch.
//Start at brown, to match the SOLID color
#define Q_QSTART 7 //3
//a/o v62-21:
// this is stolen from seg_question.c and modified for the framebuffer...
//Include Question3.h to include all mario3 sprites...
#if(defined(MARIO3) && MARIO3)
//#warning "MARIO3 is TRUE, but its #inclusion is commented-out"
#include "icons/Question3.h"
#endif
//Currently it's not possible to only include Mario3...
// This MUST be included.
#include "icons/Question.h"
#include "icons/Solid.h"
#include "icons/SolidBump.h"
#include "icons/Goomba.h"
#include "icons/GoombaDead.h"
#include "icons/1up.h"
#include "icons/Biggie.h"
#include "icons/StarV.h"
#include "icons/FlowerPowerV.h"
#include "icons/Coin.h"
#include "icons/Cloud.h"
#include "icons/Mario.h"
#include "icons/Luigi.h"
#include "icons/MarioRuns.h"
#include "icons/LuigiRuns.h"
#ifdef __QUESTION3_H__
#include "icons/Solid3.h"
#include "icons/SolidBump3.h"
#include "icons/Leaf.h"
#include "icons/TanookiSuit.h"
#include "icons/Frog.h"
#include "icons/Boot.h"
#include "icons/Hammer.h"
#include "icons/PWing.h"
// #include "icons/Flute.h" //Too Phallic for my liking...
// If it wasn't extending from the box, maybe it'd be different.
#include "icons/MusicBox.h"
#endif
//This needs to be included AFTER Question3.h if used...
// (and FlowerPowerV.h)...
#include "icons/spriteMotion.c"
//a/o v77
//APPARENTLY NUM_ICONS is no longer used.
//Excluding Solid and Question, etc...
//#define NUM_ICONS 6
//Allow the user to choose another winnings when the question-box is
//scrolling down to reveal it... for testing
//#define IMMEDIATE TRUE
//This is just a hack for testing BIGGIE with the Leaf tester, which was a
//hack in the first place.
//#define MOTION_BIGGIE TRUE //RANDOM_OVERRIDE's gotta be 2
//These are from hitDetected()
//THIS MUST NOW BE considered WITH the mario-version
// (e.g. RANDOM_OVERRIDE_Q to &spriteQ or &spriteQUESTION3 as appropriate)
//#define RANDOM_OVERRIDE 10//15//Cloud5//8//32//2//Biggie //5//Leaf //4 //8 //0 //4
//#define RANDOM_OVERRIDE_Q &spriteQ //UESTION3
//Stalls at the first sprite (initilized in p_selectedSprite, below)
//#define STAY_ON_IT TRUE
//Automatically hit after a few loops in the "Q" box
//#define AUTO_HIT TRUE
//#define AUTO_KILL_GOOMBA TRUE
//THESE DON'T BELONG HERE
// AND they shouldn't be "Q" specific, at all.
#define Q_WIDTH 16
#define Q_HEIGHT 16
#if((Q_WIDTH != FB_WIDTH) || (Q_HEIGHT != FB_HEIGHT))
#error "FB dims do not match Icon dims"
#endif
//this is just a counter to help throw in some additional randomness...
uint8_t callCount = 0;
//uint8_t qCount = 0;
//sprite_t *p_selectedSprite = &spriteLEAF; //COIN; //GOOMBA; //FLOWER; //&spriteQ;
//a/o v84: nextSprite is hokily used as selectedSprite...
// This needs to be changed.
//sprite_t *p_nextSprite = &spriteLEAF; //NULL;
const __flash sprite_t *p_nowSprite = &spriteQ;//UESTION3;
//&spriteLEAF; //NULL;
//This indicates whether we're in a "Reward"
// e.g. to draw SOLID in the background
// 1 = SOLID
// 3 = SOLID3
uint8_t nowIsReward = FALSE; //TRUE;
void initSpriteStates(const __flash sprite_t *newSprite);
//#define FB_ENABLE_PAUSE TRUE
#if(defined(FB_ENABLE_PAUSE) && FB_ENABLE_PAUSE)
#warning "FB_ENABLE_PAUSE is TRUE... this is for debugging and isn't well-implemented. DO NOT USE in an installation!"
uint8_t fb_paused = FALSE;
#endif
uint8_t pseudoRandom(void)
{
return (HSYNC_TIMER_TCNT + callCount + nowSpriteState.count);
}
uint8_t qVersion = 1;
#warning "qVersion and nowIsReward could probably be merged..."
void fbQuestion_hitDetected(void)
{
uint8_t selectedQ = 0;
if( p_nowSprite == &spriteQ)
selectedQ = 1;
#ifdef __QUESTION3_H__
else if (p_nowSprite == &spriteQUESTION3)
selectedQ = 3;
#endif
#ifdef __QUESTION3_H__
if(selectedQ == 3)
{
qVersion = selectedQ;
p_nowSprite = &spriteSOLIDBUMP3;
}
else
#endif
if(selectedQ)
{
qVersion = selectedQ;
p_nowSprite = &spriteSOLIDBUMP;
}
//As-is, the last frame (in blue, indicating death) is only visible
//briefly before scroll-back-to-question starts...
// so there's no reason to test for KILLABLE
// since it can't be killed when it's scrolling.
// There's probably a tiny fraction of a second window where it is
// possible to hit it when it's blue, and kill it... but it's TINY.
else if((p_nowSprite == &spriteGOOMBA)
&& ((nowSpriteState.count > 16) && (nowSpriteState.count < 62)))
{
p_nowSprite = &spriteDEADGOOMBA;
}
#if(defined(FB_ENABLE_PAUSE) && FB_ENABLE_PAUSE)
else
{
fb_paused = !fb_paused;
return;
}
#endif
initSpriteStates(p_nowSprite);
}
void prepReward(void)
{
if(qVersion == 1)
{
uint8_t hitReward;
//Just trying to get some randomness up in hea
#if (defined(RANDOM_OVERRIDE))
hitReward = RANDOM_OVERRIDE;
#else
static uint8_t lastReward;
do
{
//hitReward =
//(HSYNC_TIMER_TCNT + callCount + nowSpriteState.count)%20;
hitReward = pseudoRandom()%12;
//Don't allow double-goombas
} while ((lastReward == 4) && (hitReward == 4));
lastReward = hitReward;
#endif
switch(hitReward)
{
case 0:
p_nowSprite = &spriteFLOWER;
break;
case 1:
p_nowSprite = &sprite1UP;
break;
case 2:
p_nowSprite = &spriteBIG;
break;
case 3:
p_nowSprite = &spriteSTAR;
break;
case 4:
p_nowSprite = &spriteGOOMBA;
break;
case 6:
p_nowSprite = &spriteCLOUD;
break;
case 7:
p_nowSprite = &spriteMARIO;
break;
case 8:
p_nowSprite = &spriteLUIGI;
break;
default:
p_nowSprite = &spriteCOIN;
break;
}
//qCount = 0;
nowIsReward = qVersion; //selectedQ; // TRUE;
initSpriteStates(p_nowSprite);
}
#ifdef __QUESTION3_H__
else if(qVersion == 3)
{
uint8_t hitReward;
//Just trying to get some randomness up in hea
#if (defined(RANDOM_OVERRIDE))
hitReward = RANDOM_OVERRIDE;
#else
hitReward = pseudoRandom()%12;
#endif
switch(hitReward)
{
case 0:
p_nowSprite = &spriteLEAF;
break;
case 1:
p_nowSprite = &spriteCLOUD;
break;
case 2:
p_nowSprite = &spriteTANOOKI;
break;
case 3:
p_nowSprite = &spriteFROG;
break;
case 4:
p_nowSprite = &spriteBOOT;
break;
case 5:
p_nowSprite = &spriteHAMMER;
break;
case 6:
p_nowSprite = &spritePWING;
break;
// case 7:
// p_nowSprite = &spriteFLUTE;
// break;
case 8:
p_nowSprite = &spriteMUSICBOX;
break;
default:
p_nowSprite = &spriteCOIN;
break;
}
//qCount = 0;
nowIsReward = qVersion; //selectedQ; // TRUE;
initSpriteStates(p_nowSprite);
}
#endif //__QUESTION3_H__
}
//If a spriteRow is outside the icon's dimensions, draws the sky-color
//Returns TRUE if a pixel has changed
// for redrawing...
uint8_t drawSpriteRow(const __flash sprite_t *p_thisSprite, uint8_t spritePhase,
int8_t spriteRow,
uint8_t rowToDrawAt);
#if(defined(STAY_ON_IT) && STAY_ON_IT)
//Check for completion of one sprite, and setup the next...
void prepNextSprite(void)
{
}
#else
void prepNextSprite(void)
{
//a/o v84:
// The new plan is to have a defined path...
// Q -> SolidBump -> "Reward" -> Solid -> Q
// CURRENTLY: "Hit" is NYI so:
// Q -> "Reward" -> Solid -> Q
// Q Loops...
uint8_t selectedQ = 0;
if(p_nowSprite == &spriteQ)
selectedQ = 1;
#ifdef __QUESTION3_H__
else if(p_nowSprite == &spriteQUESTION3)
selectedQ = 3;
#endif
if(selectedQ)
{
//Do nothing for Q... until a hit arrives
// nowIsReward should already be FALSE
// If AUTO_HIT is true, then "after" Question-box "completes"
// act like a hit was detected...
#if(defined(AUTO_HIT) && AUTO_HIT)
fbQuestion_hitDetected();
#else
//return;
#endif
}
// SolidBump -> "reward"
else if( (p_nowSprite == &spriteSOLIDBUMP)
#ifdef __QUESTION3_H__
|| (p_nowSprite == &spriteSOLIDBUMP3)
#endif
)
{
prepReward();
}
// Mario -> MarioRuns
else if(p_nowSprite == &spriteMARIO)
{
//nowIsReward = TRUE;
p_nowSprite = &spriteMARIORUNS;
}
// Luigi -> LuigiRuns
else if(p_nowSprite == &spriteLUIGI)
{
//nowIsReward = TRUE;
p_nowSprite = &spriteLUIGIRUNS;
}
// Solid -> Q
else if((p_nowSprite == &spriteSOLID)
#ifdef __QUESTION3_H__
|| (p_nowSprite == &spriteSOLID3)
#endif
)
{
nowIsReward = FALSE;
#if(!defined(RANDOM_OVERRIDE))
#ifdef __QUESTION3_H__
if(pseudoRandom()&0x01)
p_nowSprite = &spriteQUESTION3;
else
#endif//__QUESTION3_H__
p_nowSprite = &spriteQ;
#else //RANDOM_OVERRIDE
p_nowSprite = RANDOM_OVERRIDE_Q;
#endif
}
// "Reward" -> Solid
else
{
#ifdef __QUESTION3_H__
if(nowIsReward == 3)
p_nowSprite = &spriteSOLID3;
else
#endif
p_nowSprite = &spriteSOLID;
nowIsReward = FALSE;
// p_nowSprite = &spriteSOLID;
}
initSpriteStates(p_nowSprite);
}
void initSpriteStates(const __flash sprite_t *newSprite)
{
//qCount = 0;
//.count is handled by qCount... but let's init it anyhow.
p_nowSprite = newSprite;
nowSpriteState.sprite = p_nowSprite;
nowSpriteState.count = 0;
nowSpriteState.hFlip = p_nowSprite->p_hFlip;
nowSpriteState.motion = p_nowSprite->p_motion;
//Origin is lower-left, but nextSpritePosition is upper-left...
nowSpriteState.position[0] = -(nowSpriteState.motion[0].startPosition);
nowSpriteState.position[1] = nowSpriteState.motion[1].startPosition;
nowSpriteState.dir[0] = 1;
nowSpriteState.dir[1] = 1;
nowSpriteState.layer = p_nowSprite->p_layer;
nowSpriteState.paletteNum = 0;
//No sprite associated with the camera...
cameraState.sprite = NULL;
cameraState.count = 0;
cameraState.hFlip = NadaFlip;
cameraState.motion = p_nowSprite->p_camMotion;
cameraState.position[0] = -(cameraState.motion[0].startPosition);
cameraState.position[1] = cameraState.motion[1].startPosition;
cameraState.dir[0] = 1;
cameraState.dir[1] = 1;
cameraState.layer = NadaLayer;
cameraState.paletteNum = 0;
//This is only used by the SOLID in the background for Reward...
// So probably never changes...
//otherSpriteState.hFlip = NadaFlip;
//otherSpriteState.motion = NadaMotion;
#if 0
//DEADGOOMBA -> Question-Box (directly)
if(p_selectedSprite == &spriteDEADGOOMBA)
{
if(qCount >= 16)
{
qCount = Q_QSTART; //0;
p_nextSprite = &spriteQ;
}
}
//GOOMBA -> SOLID
else if(p_selectedSprite == &spriteGOOMBA)
{
if(qCount >= GOOMBA_QCOUNT)
{
qCount = 0;
p_nextSprite = &spriteSOLID;
}
}
//COIN -> SOLID
else if(p_selectedSprite == &spriteCOIN)
{
if(qCount >= 8)
{
qCount = 0;
p_nextSprite = &spriteSOLID;
}
}
//SOLID -> Question-Box
else if(p_selectedSprite == &spriteSOLID)
{
if(qCount >= 8)
{
qCount = Q_QSTART; //0;
p_selectedSprite = &spriteQ;
}
}
//**OTHERS** (NOT Question-Box) -> SOLID
else if(p_selectedSprite != &spriteQ)
{
if(qCount >= 16)
{
qCount = 0;
//if(p_selectedSprite != &spriteSOLID)
p_nextSprite = &spriteSOLID;
//else
// p_selectedSprite = &spriteQ;
}
}
#endif //0
}
#endif //!STAY_ON_IT
// NEW MOTION-HANDLING...
//This is sort-of Motion-Handling, as well...
//Usually the sky...
void fbQ_drawBackground(spriteState_t *state)
{
//I can't recall how this used to work...
//uint8_t paletteForColor = getSpritePalette(&spriteLEAF, 0, 0);
uint8_t paletteForColor = state->paletteNum;
//probably should look into skyOverride
// for now, use the sky-color of the leaf, which is at (0,0)
//Fill the background with the sky-color...
//#define FBQ_SKYCOLOR_OVERRIDE _R
#if(defined(FBQ_SKYCOLOR_OVERRIDE))
uint8_t skyColorData = FBQ_SKYCOLOR_OVERRIDE;
#else
//uint8_t skyColorData = getRawPixelVal(, 0, 0);
uint8_t skyColorData = rawPixValToGimpColorVal(0,
state->sprite,
paletteForColor);
skyColorData = gimpPixelValToLColor(skyColorData);
#endif
int8_t camRow, camCol;
for(camRow = 0; camRow<FB_HEIGHT; camRow++)
{
for(camCol = 0; camCol<FB_WIDTH; camCol++)
{
#if(defined(FBQ_RAINBOW_SKY) && FBQ_RAINBOW_SKY)
frameBuffer[camRow][camCol] = (camRow+camCol)&0x3f;//skyColorData;
#else
frameBuffer[camRow][camCol] = skyColorData;
#endif
//Should look into framebuffer-changed stuff, here...
}
}
}
//Returns the last image-row that has changed...
// (for refresh-on-change and/or partial-refresh)
// otherwise -1 if no change.
int8_t fbQuestion_update(void) //uint8_t triggerDetected)
{
//last row that was changed...
int8_t imageChangedTillRow = -1;
#if(defined(FB_ENABLE_PAUSE) && FB_ENABLE_PAUSE)
if(fb_paused)
return -1;
#endif
//This is just used for helping to throw in some randomness for the next
//sprite after a hit...
callCount++;
// uint8_t qRow;
//Check if it's time to select the next sprite, and do-so according to
//which sprite we're on and which should follow it.
//Most of the time, a sprite is followed by SOLID, but there are
//exceptions...
/*
if(p_nextSprite == NULL)
{
prepNextSprite();
}
*/
/*
if(p_nextSprite != NULL)
{
*/
//a/o v84:
//Is this necessary with motion handling, since the sky is drawn
//separately???
setSpriteSkyColorOverride(p_nowSprite);
//This isn't right, doesn't transition at all
// it's just for testing the motion-scheme
//Testing the new transition-scheme...
/*
#if(defined(MOTION_BIGGIE) && MOTION_BIGGIE)
if(p_nextSprite == &spriteBIG)
#else
if(p_nextSprite == &spriteLEAF)
#endif
*/
//if(p_selectedSprite == &spriteLEAF) //NoGo
{
#if(defined(AUTO_KILL_GOOMBA) && AUTO_KILL_GOOMBA)
if( (p_nowSprite == &spriteGOOMBA)
&& (nowSpriteState.count >= 60) )
fbQuestion_hitDetected();
#endif
//Override for now...
//otherSpriteState.count=0;
fbQ_drawBackground(&nowSpriteState);
if(fbQ_repositionSprite(&nowSpriteState))
imageChangedTillRow = FB_HEIGHT;
if(fbQ_repositionSprite(&cameraState))
imageChangedTillRow = FB_HEIGHT;
// "otherSpriteState" needn't be repositioned, it's always
// SOLID (if used, only during a Reward)
/*
if(p_nowSprite == &spriteQUESTION3)
{
fbQ_overlaySprite(&spriteQUESTION3, NULL);
fbQ_overlaySprite(&(spriteQUESTION3[1]), NULL);
imageChangedTillRow = FB_HEIGHT;
}
*/ if(nowIsReward)
{
sprite_t * nextSolid;
#ifdef __QUESTION3_H__
if(nowIsReward == 3)
nextSolid = &spriteSOLID3;
else
#endif
nextSolid = &spriteSOLID;
//0 is foreground, so it should be drawn last
if(!GET_LAYER(nowSpriteState.layer, nowSpriteState.count))
{
//imageChangedTillRow =
//fbQ_overlaySprite(p_selectedSprite, selectedSpritePosition);
if(fbQ_overlaySprite(nextSolid, NULL))
imageChangedTillRow = FB_HEIGHT;
//imageChangedTillRow =
if(fbQ_overlaySprite(p_nowSprite, &nowSpriteState))
imageChangedTillRow = FB_HEIGHT;
}
else
{
//imageChangedTillRow =
if(fbQ_overlaySprite(p_nowSprite, &nowSpriteState))
imageChangedTillRow = FB_HEIGHT;
//imageChangedTillRow =
//fbQ_overlaySprite(p_selectedSprite, selectedSpritePosition);
if(fbQ_overlaySprite(nextSolid, NULL))
imageChangedTillRow = FB_HEIGHT;
}
}
else //Not a reward, so only one sprite is drawn...
//E.G. SOLID, 'Q' or QUESTION3... right?
{
//imageChangedTillRow =
if(fbQ_overlaySprite(p_nowSprite, &nowSpriteState))
imageChangedTillRow = FB_HEIGHT;
}
//qCount++;
nowSpriteState.count++;// = qCount;
cameraState.count = nowSpriteState.count;
//Could, e.g., test for a hard-coded value...
/*#if(defined(MOTION_BIGGIE) && MOTION_BIGGIE)
if(qCount >= (sizeof(DefaultY)*4))
#else
if(qCount >= (sizeof(LeafX)*4))
#endif
*/
if(nowSpriteState.count >= p_nowSprite->totalCount)
{
//qCount = 0;
prepNextSprite();
/*
#define LEAF_REPEAT TRUE
#if(!defined(LEAF_REPEAT) || !LEAF_REPEAT)
p_selectedSprite = p_nextSprite;
p_nextSprite = NULL;
#endif
*/
}
return imageChangedTillRow;
}
/*
//Transitioning from the Question-box to the next sprite
else if(p_selectedSprite == &spriteQ)
{
uint8_t spriteRow;
//Draw the top of the next sprite...
for(qRow=0; qRow<qCount; qRow++)
{
spriteRow = qRow - (16 - qCount);
if(drawSpriteRow(p_nextSprite, qCount, spriteRow, qRow))
imageChangedTillRow = qRow;
}
//This is kinda hokey, but should work...
// rather than displaying the "?" after it's been hit, it should
// become solid... but in most cases using p_selectedSprite==SOLID
// results in a transition straight to Q...
// so rather than changing p_selectedSprite, let's just override
// it here
spriteRow = 0;
for( ; qRow<Q_HEIGHT; qRow++)
{
if(drawSpriteRow(&spriteSOLID, qCount, spriteRow, qRow))
imageChangedTillRow = qRow;
spriteRow++;
}
}
//Transitioning back from a sprite to the question-box/solid
else
{
uint8_t displayRow;
uint8_t spriteRow = qCount;
for(displayRow = 0; displayRow < (Q_HEIGHT-qCount); displayRow++)
{
if(drawSpriteRow(p_selectedSprite,qCount,spriteRow,displayRow))
imageChangedTillRow = displayRow;
// displayRow+qCount, displayRow);
spriteRow++;
}
spriteRow = 0;
for( ; displayRow<Q_HEIGHT; displayRow++)
{
if(drawSpriteRow(p_nextSprite, qCount, spriteRow, displayRow))
imageChangedTillRow = displayRow;
// displayRow-(Q_HEIGHT-1-qCount), displayRow);
spriteRow++;
}
}
//a/o v84: This bit's avoided with motionHandling due to return...
qCount++;
if(qCount >= Q_HEIGHT)
{
qCount = 0;
p_selectedSprite = p_nextSprite;
p_nextSprite = NULL;
}
} //end of nextSprite Handling...
else //we only have a selectedSprite (nextSprite is NULL)
{
setSpriteSkyColorOverride(NULL);
for(qRow=0; qRow<Q_HEIGHT; qRow++)
{
if(drawSpriteRow(p_selectedSprite, qCount, qRow, qRow))
imageChangedTillRow = qRow; //TRUE;
}
qCount++;
//the only case where qCount should cycle is spriteQ...
// its value is %12, so could either reset it at 12, or this.. whatev
// To avoid a glitch every 21 cycles.
if(qCount >= ((255 / 12) * 12))
qCount = 0;
}
*/
return imageChangedTillRow;
}
uint8_t getSpritePalette(const __flash sprite_t *p_thisSprite, uint8_t spritePhase,
uint8_t spriteRow)
{
uint8_t thePalette;
if(p_thisSprite == &spriteFLOWER)
{
if(spriteRow<FLOWER_PALETTE1_ROW)
//data = getGimpColorVal(&spriteFLOWER,
thePalette = spritePhase%(spriteFLOWER.numPalettes-1) + 1;
//spriteRow, qCol);
else
thePalette = 0;
//data = getGimpColorVal(&spriteFLOWER, 0, spriteRow, qCol);
}
else if(p_thisSprite == &spriteGOOMBA)
{
//uint8_t gCol = qCol;
//Goomba moves by flipping horizontally...
// if((spritePhase < 16) && (spritePhase & 0x01))
// theCol = 15-qCol;
//uint8_t palette; // = qCount * p_thisSprite->numPalettes / 16;
//if(palette >= p_thisSprite->numPalettes)
// palette = p_thisSprite->numPalettes-1;
switch(spritePhase)
{
case 0:
case 1:
case 2:
case 3:
thePalette = 0;
break;
case 4:
case 5:
case 6:
thePalette = 1;
break;
case 7:
case 8:
case 9:
thePalette = 2;
break;
case 10:
case 11:
case 12:
thePalette = 3;
break;
case 13:
case 14:
case 15:
thePalette = 4;
break;
default:
thePalette = p_thisSprite->numPalettes-1;
}
//data = getGimpColorVal(&spriteGOOMBA, palette, spriteRow, gCol);
}
else
{
//data = getGimpColorVal(p_thisSprite,
thePalette = spritePhase%p_thisSprite->numPalettes;
//spriteRow, qCol);
}
return thePalette;
}
//This does NOT handle COIN, see getRowPixelValCOIN()...
// vOffset is whether the sprite is above the frame-buffer or below...
// centered = 0
// so, e.g. vOffset = spriteRow - rowToDrawAt
uint8_t getSpritePhase(const __flash sprite_t *p_thisSprite, uint8_t qCount, int8_t
vOffset)
{
uint8_t spritePhase = qCount;
if(p_thisSprite == &spriteQ)
{
switch(spritePhase%12)
{
case 0:
case 1:
case 2:
case 9:
case 10:
case 11:
spritePhase = 0; //yellow background
break;
case 3:
case 4:
case 7:
case 8:
spritePhase = 1; //red background
break;
case 5:
case 6:
default:
spritePhase = 2; //brown background
break;
}
}
//else if(p_thisSprite == &spriteCOIN) //handled in getRowPixelValCOIN()
else if(p_thisSprite == &spriteGOOMBA)
{
if (vOffset < 0) //(spriteRow < rowToDrawAt)
spritePhase = 0;
if (vOffset > 0) //(spriteRow > rowToDrawAt)
spritePhase = GOOMBA_QCOUNT;
else
spritePhase /=3;
}
return spritePhase;
}
/*
//spritePhase replaces qCount... for determining e.g. the color palette and
//the motion of the goomba...
// This does *NOT* handle COIN... use getRowPixelValCOIN() instead.
uint8_t drawSpriteRow(const __flash sprite_t *p_thisSprite, uint8_t qCount,
//uint8_t spritePhase,
int8_t spriteRow,
uint8_t rowToDrawAt)
{
uint8_t rowChanged = FALSE;
uint8_t qCol;
uint8_t spritePhase;
spritePhase = getSpritePhase(p_thisSprite, qCount,
((int8_t)spriteRow - rowToDrawAt) );
//This may get overridden (for the sky)
uint8_t thePalette = getSpritePalette(p_thisSprite, spritePhase,
spriteRow);
for(qCol=0; qCol<Q_WIDTH; qCol++)
{
// Should use readImageByte... but it's specific to FB_WIDTH
//uint8_t data=
// pgm_read_byte((uint8_t *)(&((p_image)[(qRow)*Q_WIDTH+(qCol)])));
uint8_t data;
int8_t theCol = qCol;
if(p_thisSprite == &spriteGOOMBA)
{
//uint8_t gCol = qCol;
//Goomba moves by flipping horizontally...
if((spritePhase < 16) && (spritePhase & 0x01))
theCol = 15-qCol;
}
//Early test, just slide across the screen
if(p_thisSprite == &spriteLEAF)
{
theCol = qCol-spritePhase;
}
//If rawPixVal == 0, then draw the sky-color...
uint8_t rawPixVal;
if((theCol >= FB_WIDTH) || (theCol < 0))
rawPixVal = 0;
else if((spriteRow < 0) || (spriteRow >= Q_HEIGHT))
rawPixVal = 0;
else if(p_thisSprite == &spriteCOIN)
rawPixVal = getRawPixelValCOIN(spritePhase, spriteRow, theCol);
else
rawPixVal = getRawPixelVal(p_thisSprite, spriteRow, theCol);