/
MainGame.cpp
1945 lines (1687 loc) · 55.8 KB
/
MainGame.cpp
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
#include "MainGame.h"
void NewRow();
void CheckMatches();
void SetHoverers2(int firsthoverer, int hovertime, int addflags);
void SetHoverers(int firsthoverer, int hovertime, int addflags);
// Stuff defined in this file:
// . the data structures that store the configuration of
// the stack of panels
// . the main game routine
// (rising, timers, falling, cursor movement, swapping, landing)
// . the matches-checking routine
int NewDir;
int GameTimeRender;
int P1ScoreRender;
int MrStopState;
int MrStopTimer;
int MrStopAni[25];
// The stack of panels.
int P1StackPanels[96];
// Twelve rows of 8 ints each, the first 6 representing
// the panels on that row.
// A panel's color can be retrieved using P1Stack[row<<3+col]
// Each space on the stack of panels has a timer.
int P1StackTimers[96];
// A panel's timer indicates for how many more frames it will:
// . be swapping
// . sit in the MATCHED state before being set POPPING
// . sit in the POPPING state before actually being POPPED
// . sit and be POPPED before disappearing for good
// . hover before FALLING
// depending on which one of these flags is set on the panel.
// Each space on the stack of panels has flags
// that define the state it's in.
int P1StackFlags[96];
#define FLAG_SWAPPING 1 // bit 0
#define FLAG_FROMLEFT 2 // bit 1
// Bit 0 is set if the panel is swapping.
// The panel's timer then counts down from 3 to 0,
// causing the swap to end 3 frames later.
// The timer is also used to offset the panel's
// position on the screen.
// Bit 1 indicates from which direction the panel
// is swapping:
// 0 - from right
// 1 - from left
#define FLAG_DONTSWAP 4 // bit 2
// In some cases a swapping panel shouldn't be allowed to swap
// again until it's done with the swapping it's doing already.
// In these cases bit 2, FLAG_DONTSWAP, should be set.
#define FLAG_MATCHED 8 // bit 3
// This flag is set when a panel's matched, then its timer counts
// down until it reaches 0, at which time it will become:
#define FLAG_POPPING 16 // bit 4
// Popping. All the panels in a match become popping at once,
// but their timers for remaining in this state will be higher
// depending on their place in the match (FLAG_MATCHINDEX).
#define FLAG_POPPED 32 // bit 5
// This flag indicates that panel has popped, but it's still
// there until the last panel in the match pops. When
// its timer reaches 0 the panel is GONE!
#define FLAG_HOVERING 64 // bit 6
// This panel is floating and cannot be touched until
// its timer reaches 0 and it begins to fall.
#define FLAG_FALLING 128 // bit 7
#define FLAG_CHAINING 256 // bit 8
// A match made with a chain panel is a chain match...
// Chain panels are de-flagged during the match-checking
// routine, if they are eligible for a match but didn't make
// one, and also are not sitting on top of a hovering or
// swapping panel. The chain flag must remain set on the panel
// until it pops.
#define FLAG_DIMMED 512 // bit 9
// This panel is on the bottom row and isn't in play.
#define FLAG_LANDING 1024 // bit 10
// A panel that landed just recently. This flag is set
// so that the timer can be used to index the correct
// frame to be drawn for the panel (the 'bounce' effect).
// These next definitions exclude panels in certain states
// from being acted upon in certain ways.
// Bits 11-31 are reserved for possible future needs
#define EXCLUDE_HOVER 632
// If a panel is matched, popping, popped, hovering,
// or falling it won't get set hovering.
#define EXCLUDE_MATCH 761
// If a panel is swapping, matched, popping, popped, hovering,
// dimmed, or falling it isn't eligible for a match.
#define EXCLUDE_SWAP 636
// A panel is untouchable when matched, popping, popped, hovering,
// dimmed, or is a swapping empty space below a panel (DONTSWAP).
// And finally, each panel has a couple tags.
// Unlike the timers and flags, they don't need to be cleared
// when their data is no longer valid, because they should
// only be checked when the data is surely valid.
int P1StackTags[96];
#define TAG_COMBOINDEX 127 // bits 0-6
#define TAG_COMBOSIZE 16256 // bits 7-13
#define TAG_CHAININDEX 4294950912 // bits 14-31 (hahaha)
// Stack displacement.
int P1StackDisplacement;
// This variable indicates how far below the top of the play
// area the top row of panels actually is.
// This variable being decremented causes the stack to rise.
// During the automatic rising routine, if this variable is 0,
// it's reset to 15, all the panels are moved up one row,
// and a new row is generated at the bottom.
// Only when the displacement is 0 are all 12 rows "in play."
int DoMatchesCheck;
// if this gets set non-zero a matches-check will occur for this
// frame.
int P1DangerCol[6]; // set 1 if this column is near the top
int P1DangerTimer; // decided bounce frame when in danger
int P1DifficultyLV;
#define VEASY 0
#define EASY 1
#define NORMAL 2
#define HARD 3
#define VHARD 4
int P1SpeedLV; // The player's speed level decides the amount of time
// the stack takes to rise automatically
int P1RiseTimer; // When this value reaches 0, the stack will rise a pixel
int P1RiseLock; // If the stack is rise locked, it won't rise until it is
// unlocked.
int P1HasRisen; // set once the stack rises once during the game
int P1StopTime;
int P1StopTimeTimer;
int StopTime_Combo[2][5];
int StopTime_Chain[2][5];
int GameTime;
int GameTimeMode;
int GameTimeTimer;
#define TIME_ELAPSED 1
#define TIME_REMAINING 2
int ScoreMode;
#define SCOREMODE_TA 1
#define SCOREMODE_PDP64 2
int P1Score; // der skore
int P1ChainCounter; // how high is the current chain?
// The following variables keep track of stuff:
int bottomrow; // row number of the bottom row that's "in play"
int PanelsInTopRow; // boolean, panels in the top row (danger)
int PanelsInSecondRow; // changes music state
int Count_ActivePanels;
int Count_ChainPanels;
// These change depending on the difficulty and speed levels:
int FRAMECOUNT_HOVER;
int FRAMECOUNT_MATCH;
int FRAMECOUNT_FLASH;
int FRAMECOUNT_POP;
int FRAMECOUNT_RISE;
// Player input stuff:
int P1ManualRaise; // set until raising is completed
int P1ManualRaiseYet; // if not set, no actual raising's been done yet
// since manual raise button was pressed
int P1PreventManualRaise;
int P1Swap1; // attempt to initiate a swap on this frame
int P1Swap2;
int P1CurWaitTime; // number of ticks to wait before the cursor begins
// to move quickly... it's based on P1CurSensitivity
int P1CurTimer; // number of ticks for which a new direction's been pressed
int P1CurDir; // the direction pressed
int P1CurRow; // the row the cursor's on
int P1CurCol; // the column the left half of the cursor's on
#define DIR_UP 1
#define DIR_DOWN 2
#define DIR_LEFT 3
#define DIR_RIGHT 4
int P1CurMoveAloud; // this is set if the cursor movement sound should be played
// score lookup tables
int Score_Combo_PdP64[40];
int Score_Combo_TA[31];
int Score_Chain_TA[14];
int Input_Swap1Pressed;
int Input_Swap2Pressed;
int Input_DirPressed; // last dir pressed
int P1GameOver;
int Font_NumRed;
int Font_NumBlue;
int P1StackPosX; // Position of the play area on the screen
int P1StackPosY;
int P1ScoreDisplay;
int P1ScoreDigits[5];
int GameTimeDisplay;
int GameTimeDisplayPosX;
int GameTimeDisplayPosY;
int GameTimeDigits[7];
int Graphics_TIME;
int Graphics_Ready321;
int P1SpeedLVDisplay;
int P1SpeedLVRender;
int P1SpeedLVDigits[3];
int Graphics_level;
int Graphics_MrStop[2];
int Graphics_Difficulty[5];
int Graphics_Panels[9];
int Graphics_Cursor[2];
int bouncetable[13];
int dangerbouncetable[30];
int TimeSlideAni[65];
int CardAni[50];
int Graphics_ComboCards;
int Graphics_ChainCards;
int ComboCardsQueue[50];
int ComboCardsQueueLength;
int ChainCards16Queue[50];
int ChainCards16QueueLength;
int ChainCards21Queue[50];
int ChainCards21QueueLength;
int NumConfettis;
#define MAXCONFETTIS 8
int Confettis[8][5];
#define CONFETTI_TIMER 0
#define CONFETTI_RADIUS 1
#define CONFETTI_ANGLE 2
#define CONFETTI_X 3
#define CONFETTI_Y 4
int ConfettiAni[48];
int ConfettiBuf[6][2];
#define CONFETTI_STARTTIMER 40
#define CONFETTI_STARTRADIUS 150
int Graphics_Controller;
int Graphics_Controller_Up;
int Graphics_Controller_Down;
int Graphics_Controller_Left;
int Graphics_Controller_Right;
int Graphics_Controller_ABXY;
int Graphics_Controller_L;
int Graphics_Controller_R;
void Controls_NewGame()
{
Input_Swap1Pressed=0;
Input_Swap2Pressed=0;
Input_DirPressed=0;
P1ManualRaise=0;
P1ManualRaiseYet=0;
}
void SetupGame_Any()
{
int a;
P1StackPosX=75;
P1StackPosY=21;
switch(P1DifficultyLV)
{
case EASY:
FRAMECOUNT_HOVER=12;
FRAMECOUNT_MATCH=61;
FRAMECOUNT_FLASH=16;
FRAMECOUNT_POP=9;
case NORMAL:
FRAMECOUNT_HOVER=9;
FRAMECOUNT_MATCH=50;
FRAMECOUNT_FLASH=13;
FRAMECOUNT_POP=8;
case HARD:
FRAMECOUNT_HOVER=6;
FRAMECOUNT_MATCH=37;
FRAMECOUNT_FLASH=8;
FRAMECOUNT_POP=7;
}
P1GameOver=0;
PanelsInTopRow=0;
P1HasRisen=0;
Count_ActivePanels=0;
Count_ChainPanels=0;
P1ChainCounter=0;
ComboCardsQueueLength=0;
ChainCards16QueueLength=0;
ChainCards21QueueLength=0;
NumConfettis=0;
P1Score=0;
P1ScoreRender=1;
P1StopTime=0;
P1StopTimeTimer=0;
P1SpeedLVRender=1;
P1DangerTimer=0;
P1RiseTimer=FRAMECOUNT_RISE;
for(a=0;a<96;a++)
{
P1StackPanels[a]=0;
P1StackFlags[a]=0;
P1StackTimers[a]=0;
P1StackTags[a]=0;
}
P1StackDisplacement=0;
P1CurRow=6;
P1CurCol=2;
Controls_NewGame();
}
// The engine routine.
void PdP()
{
// The main game routine has five phases:
// 1. Decrement timers, act on expired ones
// 2. Move falling panels down a row
// 3. Do things according to player input
// 4. Make falling panels land
// 5. Possibly do a matches-check
// During these phases the entire StackPanels will be examined
// several times, from first to last (or last to first).
// Here are defined the necessary counters for iterating through
// the StackPanels and StackTimers:
int row, col; // used for iterating through the StackPanels
int panel; // used when row and col are avoidable
int counter; // an extra general-purpose counter
// other general-purpose things:
int whatever, something, somethingelse;
if(P1StopTime)
{
P1StopTimeTimer--;
if(!P1StopTimeTimer)
{
P1StopTime--;
if(P1StopTime) P1StopTimeTimer=60;
}
}
if(P1StackDisplacement) bottomrow=10;
else bottomrow=11; // the 12th row (row 11) is only "in play"
// when the stack displacement is 0
// and there are panels in the top row
// count the number of panels in the top row (danger)
PanelsInTopRow=0;
for(panel=0;panel<6;panel++)
{
if(P1StackPanels[panel])
{
PanelsInTopRow=1;
P1DangerCol[panel]=1;
}
else P1DangerCol[panel]=0;
}
if(PanelsInTopRow)
{
if(!P1StopTime)
{
P1DangerTimer--;
if(P1DangerTimer<0) P1DangerTimer=17;
}
}
PanelsInSecondRow=0;
for(panel=8;panel<14;panel++)
{
if(P1StackPanels[panel])
PanelsInSecondRow=1;
}
if(!P1StackDisplacement && P1HasRisen)
{
if(!PanelsInTopRow)
{
NewRow();
}
}
if( Count_ActivePanels ) P1RiseLock=1;
else P1RiseLock=0;
if(!P1StackDisplacement && PanelsInTopRow && !P1RiseLock && !P1StopTime)
P1GameOver=1;
// Phase 0 //////////////////////////////////////////////////////////////
// Stack automatic rising
if(P1SpeedLV && !P1ManualRaise) // only rise if speed LV is non-zero
{
if(!P1StopTime && !P1RiseLock)
{
P1RiseTimer--;
if(!P1RiseTimer) // try to rise
{
if(!P1StackDisplacement)
{
if(P1HasRisen || PanelsInTopRow)
{
//P1GameOver=1;
}
else
{
NewRow();
P1StackDisplacement=23;
P1HasRisen=1;
}
}
else
{
P1StackDisplacement--;
if(!P1StackDisplacement)
{
P1PreventManualRaise=0;
if(PanelsInTopRow)
{
for(panel=88;panel<94;panel++)
if(P1StackFlags[panel] & FLAG_DIMMED)
P1StackFlags[panel]-=FLAG_DIMMED;
bottomrow=11;
}
else
{
NewRow();
}
}
}
P1RiseTimer=FRAMECOUNT_RISE;
}
}
}
// Phase 1 . ///////////////////////////////////////////////////////
// Falling
for(row=bottomrow;row>=0;row--)
{
panel=row<<3;
for(col=0;col<6;col++)
{
if(P1StackFlags[panel] & FLAG_FALLING)
{
// if there's no panel below a falling panel,
// it must fall one row.
// I'm gonna assume there's no panel below,
// because the falling panel should've landed on
// it during the last frame if there was.
P1StackPanels[panel+8]=P1StackPanels[panel];
P1StackFlags[panel+8]=P1StackFlags[panel];
P1StackTimers[panel+8]=0;
P1StackPanels[panel]=0;
P1StackFlags[panel]=0;
// the timer can be left behind because it should be 0.
// the tags can be left behind because they're not important
// until a panel is stuck in position.
}
panel++;
}
}
// Phase 2. /////////////////////////////////////////////////////////////
// Timer-expiring actions
for(row=bottomrow;row>=0;row--)
{
panel=row<<3;
for(col=0;col<6;col++)
{
// first of all, we do Nothin' if we're not even looking
// at a space with any flags.
if(P1StackFlags[panel])
{
if(P1StackTimers[panel])
{
P1StackTimers[panel]--;
if(!P1StackTimers[panel])
{
if(P1StackFlags[panel] & FLAG_SWAPPING)
{
// a swap has completed here.
P1StackFlags[panel]-=FLAG_SWAPPING;
if(P1StackFlags[panel] & FLAG_DONTSWAP)
P1StackFlags[panel]-=FLAG_DONTSWAP;
if(P1StackFlags[panel] & FLAG_FROMLEFT)
{
P1StackFlags[panel]-=FLAG_FROMLEFT;
something=1;
} else something=0;
// Now there are a few cases where some hovering must
// be done.
if(P1StackPanels[panel])
{
if(row!=bottomrow)
{
if(!P1StackPanels[panel+8])
{
SetHoverers2(panel,FRAMECOUNT_HOVER,0);
// if there is no panel beneath this panel
// it will begin to hover.
// CRAZY BUG EMULATION:
// the space it was swapping from hovers too
if(something)
{
if(P1StackFlags[panel-1] & FLAG_FALLING)
SetHoverers2(panel-1,FRAMECOUNT_HOVER,0);
}
else
{
if(P1StackFlags[panel+1] & FLAG_FALLING)
SetHoverers(panel+1,FRAMECOUNT_HOVER+1,0);
}
}
else
{
// swap may have landed on a hover
if(P1StackFlags[panel+8] & FLAG_HOVERING)
SetHoverers2(panel,FRAMECOUNT_HOVER,0);
}
}
}
else
{
// an empty space finished swapping...
// panels above it hover
SetHoverers(panel-8,FRAMECOUNT_HOVER+1,0);
}
// swap completed, a matches-check will occur this frame.
DoMatchesCheck=1;
}
else
{
if(P1StackFlags[panel] & FLAG_HOVERING)
{
// This panel is no longer hovering.
// it will now fall without sitting around
// for any longer!
P1StackFlags[panel]-=FLAG_HOVERING;
if(P1StackPanels[panel+8])
{
P1StackFlags[panel]=P1StackFlags[panel] | FLAG_LANDING;
P1StackTimers[panel]=12;
DoMatchesCheck=1;
}
else
{
P1StackFlags[panel]+=FLAG_FALLING;
P1StackPanels[panel+8]=P1StackPanels[panel];
P1StackFlags[panel+8]=P1StackFlags[panel];
P1StackTimers[panel+8]=0;
P1StackPanels[panel]=0;
P1StackFlags[panel]=0;
}
}
else
{
if(P1StackFlags[panel] & FLAG_LANDING)
P1StackFlags[panel]-=FLAG_LANDING;
else
{
if(P1StackFlags[panel] & FLAG_MATCHED)
{
P1StackFlags[panel]-=FLAG_MATCHED;
// This panel's match just finished the whole
// flashing and looking distressed thing.
// It is given a pop time based on its place
// in the match.
P1StackFlags[panel]+=FLAG_POPPING;
something=P1StackTags[panel] & TAG_COMBOINDEX;
P1StackTimers[panel]=something*FRAMECOUNT_POP;
}
else
{
if(P1StackFlags[panel] & FLAG_POPPING)
{
P1Score+=10;
P1ScoreRender=1;
// this panel just popped
// Now it's invisible, but sits and waits
// for the last panel in the combo to pop
// before actually being removed.
something=P1StackTags[panel] & TAG_COMBOSIZE;
something=something>>7;
whatever=P1StackTags[panel] & TAG_COMBOINDEX;
// If it is the last panel to pop,
// it should be removed immediately!
if(something==whatever) //size==index
{
P1StackPanels[panel]=0;
if(P1StackFlags[panel] & FLAG_CHAINING)
Count_ChainPanels--;
P1StackFlags[panel]=0;
SetHoverers(panel-8,FRAMECOUNT_HOVER+1,FLAG_CHAINING);
}
else
{
P1StackFlags[panel]-=FLAG_POPPING;
P1StackFlags[panel]+=FLAG_POPPED;
P1StackTimers[panel]
=(something-whatever)*FRAMECOUNT_POP;
}
something=P1StackTags[panel] & TAG_CHAININDEX;
something=something>>14;
if(!something) something=1;
// SFX_Pop_Play[0]=something;
// SFX_Pop_Play[1]=whatever;
}
else
{
if(P1StackFlags[panel] & FLAG_POPPED)
{
// It's time for this panel
// to be gone forever.
P1StackPanels[panel]=0;
if(P1StackFlags[panel] & FLAG_CHAINING)
Count_ChainPanels--;
P1StackFlags[panel]=0;
// Any panels sitting on top of it
// hover and are flagged as CHAINING
SetHoverers(panel-8,FRAMECOUNT_HOVER+1,FLAG_CHAINING);
}
else
{
// what the heck.
// if a timer runs out and the routine can't
// figure out what flag it is, tell brandon.
}
}
}
}
}
}
// the timer-expiring action has completed
}
}
}
panel++;
}
}
// Phase 3. /////////////////////////////////////////////////////////////
// Actions performed according to player input
// CURSOR MOVEMENT
P1CurMoveAloud=0;
something=0; whatever=0;
if(!P1CurTimer) something=1;
if(P1CurTimer==P1CurWaitTime) whatever=1;
if(something || whatever)
{
if(P1CurDir==DIR_UP)
{ if(P1CurRow>0)
{ P1CurRow--;
P1CurMoveAloud=1;
}
} else
{ if(P1CurDir==DIR_DOWN)
{ if(P1CurRow<bottomrow)
{ P1CurRow++;
P1CurMoveAloud=1;
}
} else
{ if(P1CurDir==DIR_LEFT)
{ if(P1CurCol>0)
{ P1CurCol--;
P1CurMoveAloud=1;
}
} else
{ if(P1CurDir==DIR_RIGHT)
{ if(P1CurCol<4)
{ P1CurCol++;
P1CurMoveAloud=1;
}
}
}
}
}
}
if(!whatever)
{
P1CurTimer++;
// if(P1CurMoveAloud && something) SFX_P1Cursor_Play=1;
}
// SWAPPING
if(P1Swap1 || P1Swap2)
{
panel=(P1CurRow<<3)+P1CurCol;
// in order for a swap to occur, one of the two panels in
// the cursor must not be a non-panel.
if(P1StackPanels[panel] || P1StackPanels[panel+1])
{
// also, both spaces must be swappable.
something=P1StackFlags[panel] & EXCLUDE_SWAP;
whatever=P1StackFlags[panel+1] & EXCLUDE_SWAP;
if(!something && !whatever)
{
something=0;
whatever=0;
if(P1CurRow>0)
{
something=P1StackFlags[panel-8] & FLAG_HOVERING;
whatever=P1StackFlags[panel-7] & FLAG_HOVERING;
}
if(!something && !whatever)
{
something=P1StackPanels[panel];
P1StackPanels[panel]=P1StackPanels[panel+1];
P1StackPanels[panel+1]=something;
something=P1StackFlags[panel] & FLAG_CHAINING;
whatever=P1StackFlags[panel+1] & FLAG_CHAINING;
P1StackFlags[panel]=FLAG_SWAPPING | whatever;
P1StackFlags[panel+1]=FLAG_SWAPPING | something | FLAG_FROMLEFT;
P1StackTimers[panel]=3;
P1StackTimers[panel+1]=3;
// SFX_Swap_Play=1;
if(P1CurRow!=bottomrow)
{
something=0;
if(!P1StackPanels[panel+8]) something=1;
else
{ if(P1StackFlags[panel+8] & FLAG_FALLING) something=1; }
if(P1StackPanels[panel] && something)
P1StackFlags[panel]+=FLAG_DONTSWAP;
something=0;
if(!P1StackPanels[panel+9]) something=1;
else
{ if(P1StackFlags[panel+9] & FLAG_FALLING) something=1; }
if(P1StackPanels[panel+1] && something)
P1StackFlags[panel+1]+=FLAG_DONTSWAP;
}
if(P1CurRow>0)
{
if(!P1StackPanels[panel])
{ if(P1StackPanels[panel-8])
P1StackFlags[panel]+=FLAG_DONTSWAP;
}
if(!P1StackPanels[panel+1])
{ if(P1StackPanels[panel-7])
P1StackFlags[panel+1]+=FLAG_DONTSWAP;
}
}
}
}
}
P1Swap1=0;
P1Swap2=0;
}
// MANUAL STACK RAISING
if(P1ManualRaise)
{
if(!P1RiseLock)
{
if(!P1StackDisplacement)
{
if(P1HasRisen)
{
if(PanelsInTopRow)
{
P1GameOver=1;
}
}
else
{
NewRow();
P1StackDisplacement=23;
P1HasRisen=1;
}
}
else
{
P1HasRisen=1;
P1StackDisplacement--;
if(P1StackDisplacement==1)
{
P1ManualRaise=0;
P1RiseTimer=1;
if(!P1PreventManualRaise){P1Score++;P1ScoreRender=1;}
P1PreventManualRaise=1;
}
}
if(!P1ManualRaiseYet) P1ManualRaiseYet=1; //ehhhh
P1StopTime=0;
P1StopTimeTimer=0;
}
else
if(!P1ManualRaiseYet) P1ManualRaise=0;
// if the stack is rise locked when you press the raise button,
// the raising is cancelled
}
// Phase 4. /////////////////////////////////////////////////////////////
// Now falling panels will land if they have something to land on that
// isn't falling as well.
for(row=bottomrow;row>=0;row--)
{
panel=row<<3;
for(col=0;col<6;col++)
{
if(P1StackFlags[panel] & FLAG_FALLING)
{
// if it's on the bottom row, it should surely land
if(row==bottomrow)
{
P1StackFlags[panel]-=FLAG_FALLING;
P1StackFlags[panel]=P1StackFlags[panel] | FLAG_LANDING;
P1StackTimers[panel]=12;
DoMatchesCheck=1;
// SFX_Land_Play=1;
}
else
{
if(P1StackPanels[panel+8])
{
// if there's a panel below, this panel's gonna land
// unless the panel below is falling.
something=P1StackFlags[panel+8] & FLAG_FALLING;
if(!something)
{
P1StackFlags[panel]-=FLAG_FALLING;
// if it lands on a hovering panel, it inherits
// that panel's hover time.
something=P1StackFlags[panel+8] & FLAG_HOVERING;
if(something)
{
SetHoverers(panel,P1StackTimers[panel+8],0);
}
else
{
P1StackFlags[panel]=P1StackFlags[panel] | FLAG_LANDING;
P1StackTimers[panel]=12;
}
DoMatchesCheck=1;
// SFX_Land_Play=1;
}
}
}
}
panel++;
}
}
// Phase 5. /////////////////////////////////////////////////////////////
// If a swap completed, one or more panels landed, or a new row was
// generated during this tick, a matches-check is done.
if(DoMatchesCheck) CheckMatches();
// if at the end of the routine there are no chain panels, the chain ends.
if(P1ChainCounter)
{
if(!Count_ChainPanels)
{
P1ChainCounter=0;
}
}
if(P1Score>99999) P1Score=99999;
GameTimeTimer--;
if(!GameTimeTimer)
{
GameTimeTimer=60;
switch(GameTimeMode)
{
case TIME_REMAINING:
GameTime--;
if(GameTime<0) GameTime=0;
// if(!GameTime) SFX_Bell_Play=25;
// else if(GameTime<15) SFX_Bell_Play=24;
case TIME_ELAPSED:
GameTime++;
if(GameTime>359999) GameTime=359999;
}
GameTimeRender=1;
}
}
////////////////////////////////////////////////////////////////////////////
// The matches-checking routine.
// This array is used to remember which panels were matched.
int MatchedPanels[96];
void CheckMatches()
{
int row = 0, col = 0, panel = 0,count = 0,oldpanel = 0;
int ischain = 0;
int firstpanelrow = 0, firstpanelcol = 0;
int comboindex = 0, combosize = 0;
int something = 0, whatever = 0;
for(panel=0;panel<96;panel++) MatchedPanels[panel]=0;
// check vertical matches
count=0;
for(col=0;col<6;col++)
{
panel=col;
oldpanel=0;
for(row=0;row<bottomrow+1;row++)