-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgame.c
2246 lines (2111 loc) · 82.6 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
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
/*
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
Alternatively, the contents of this file may be used under the terms
of the GNU Lesser General Public license (the "LGPL License"), in which case the
provisions of LGPL License are applicable instead of those
above.
For feedback and questions about my Files and Projects please mail me,
Alexander Matthes (Ziz) , zizsdl_at_googlemail.com
*/
#include "game.h"
#include "lettering.h"
#include "settings.h"
#include "c4a.h"
#include "music.h"
#include <stdlib.h>
#include <string.h>
int playernumber;
int countdown;
int game_counter;
int insert_name;
int choosen_letter;
char myhighscore_name[3];
int star_add;
typedef SDL_Surface *PSDL_Surface;
PSDL_Surface stone_texture[9];
PSDL_Surface trophy_texture[4];
Sint32 w=0;
Sint32 posx[4],posy[4];
Sint32 pointposx[2*TIMEOUT],pointposy[2*TIMEOUT];
signed char is_change;
int pointstart;
int timeout;
char direction;
tstone stone[7][16];
int points;
int gameTime;
int timeStep;
int realTime;
#define START_TIME 120000
#define POINTS_GOAL 100000
#define LIKELYHOOD 8
pchange firstchange;
pparticle firstparticle;
char pause=0;
int chain;
int chain_break;
int oldchain;
typedef struct sPointVis *pPointVis;
typedef struct sPointVis {
int points;
int age;
pPointVis next;
} tPointVis;
pPointVis first_pointVis;
void add_pointVis(int p)
{
pPointVis mom = (pPointVis)malloc(sizeof(tPointVis));
mom->points = p;
mom->age = 0;
mom->next = first_pointVis;
first_pointVis = mom;
}
#define POINTAGE 4000
void calc_pointVis(int steps)
{
pPointVis mom = first_pointVis;
pPointVis last = NULL;
while (mom)
{
mom->age += steps;
if (mom->age > POINTAGE)
{
pPointVis next = mom->next;
free(mom);
if (last)
last->next = next;
else
first_pointVis = next;
mom = next;
}
last = mom;
if (mom)
mom = mom -> next;
}
}
void delete_pointVis()
{
while (first_pointVis)
{
pPointVis next = first_pointVis -> next;
free(first_pointVis);
first_pointVis = next;
}
}
void test_and_set_chain()
{
char found = 0;
int x,y;
for (x=0;x<16;x++)
for (y=0;y<7;y++)
if (stone[y][x].falling)
{
found = 1;
break;
}
if (!found)
{
if (chain_break>0)
chain_break--;
else
chain = 0;
}
}
Sint32 get_type_color_h(int type,int w)
{
if (type<6)
return type*SP_PI/3;
switch (type) //special stone
{
case 6: return w << 4;
case 7: return (spSin(w*13)+(1<<SP_ACCURACY)>>SP_HALF_ACCURACY)*(SP_PI/12>>SP_HALF_ACCURACY);
}
return 0;
}
Uint8 get_type_color_s(int type,int w)
{
if (type<6)
return 255;
switch (type) //special stone
{
case 6: return 32;
case 7: return 255;
}
return 0;
}
Uint8 get_type_color_v(int type,int w)
{
if (type==2) //color blindness optimization
return 210;
if (type<6)
return 255;
switch (type) //special stone
{
case 6: return 255;
case 7: return ((spSin(w*64)*63)>>SP_ACCURACY)+96;
}
return 64;
}
#define GET_TYPE_COLOR(type,w) spGetHSV(get_type_color_h(type,w),get_type_color_s(type,w),get_type_color_v(type,w))
int last_win_type;
pwinsituation search_win_situation()
{
pwinsituation finalresult = NULL;
int x,y;
for (x=0;x<16;x++)
for (y=0;y<6;y++)
{
if (stone[y ][ x ].type==8 ||
stone[y+1][ x ].type==8 ||
stone[y ][(x+1)%16].type==8 ||
stone[y+1][(x+1)%16].type==8)
continue;
if ((stone[y][x].type==6 && stone[y+1][x].type==6 && stone[y][(x+1)%16].type==6)
||
(stone[y][x].type==6 && stone[y+1][x].type==6 &&
(stone[y][(x+1)%16].type==stone[y+1][(x+1)%16].type || stone[y+1][(x+1)%16].type==6))
||
(stone[y][x].type==6 &&
(stone[y+1][x].type==stone[y ][(x+1)%16].type || stone[y ][(x+1)%16].type==6) &&
(stone[y+1][x].type==stone[y+1][(x+1)%16].type || stone[y+1][(x+1)%16].type==6))
||
(stone[y][x].type>=0 &&
(stone[y][x].type==stone[y+1][ x ].type || stone[y+1][ x ].type==6) &&
(stone[y][x].type==stone[y ][(x+1)%16].type || stone[y ][(x+1)%16].type==6) &&
(stone[y][x].type==stone[y+1][(x+1)%16].type || stone[y+1][(x+1)%16].type==6)))
{
pwinsituation result=(pwinsituation)malloc(sizeof(twinsituation));
result->x=x;
result->y=y;
result->next=finalresult;
char found=1;
char noticed[7][16];
memset(noticed,0,7*16);
noticed[y][x]=1;
int type=stone[y][x].type;
if (type == 6)
type = stone[y+1][x].type;
if (type == 6)
type = stone[y ][(x+1)%16].type;
if (type == 6)
type = stone[y+1][(x+1)%16].type;
last_win_type = type;
while (found)
{
found=0;
pwinsituation situation=result;
while (situation)
{
//left
if (noticed[situation->y][(situation->x+15)%16]==0 &&
(stone[situation->y][(situation->x+15)%16].type==type ||
stone[situation->y][(situation->x+15)%16].type==6))
{
pwinsituation newsituation=(pwinsituation)malloc(sizeof(twinsituation));
newsituation->x=(situation->x+15)%16;
newsituation->y=situation->y;
newsituation->type=stone[situation->y][(situation->x+15)%16].type;
newsituation->next=result;
result=newsituation;
found=1;
noticed[situation->y][(situation->x+15)%16]=1;
}
//Right
if (noticed[situation->y][(situation->x+1)%16]==0 &&
(stone[situation->y][(situation->x+1)%16].type==type ||
stone[situation->y][(situation->x+1)%16].type==6))
{
pwinsituation newsituation=(pwinsituation)malloc(sizeof(twinsituation));
newsituation->x=(situation->x+1)%16;
newsituation->y=situation->y;
newsituation->type=stone[situation->y][(situation->x+1)%16].type;
newsituation->next=result;
result=newsituation;
found=1;
noticed[situation->y][(situation->x+1)%16]=1;
}
//Down
if (situation->y>0)
{
if (noticed[situation->y-1][situation->x]==0 &&
(stone[situation->y-1][situation->x].type==type ||
stone[situation->y-1][situation->x].type==6))
{
pwinsituation newsituation=(pwinsituation)malloc(sizeof(twinsituation));
newsituation->x=situation->x;
newsituation->y=situation->y-1;
newsituation->type=stone[situation->y-1][situation->x].type;
newsituation->next=result;
result=newsituation;
found=1;
noticed[situation->y-1][situation->x]=1;
}
}
//Up
if (situation->y<6)
{
if (noticed[situation->y+1][situation->x]==0 &&
(stone[situation->y+1][situation->x].type==type ||
stone[situation->y+1][situation->x].type==6))
{
pwinsituation newsituation=(pwinsituation)malloc(sizeof(twinsituation));
newsituation->x=situation->x;
newsituation->y=situation->y+1;
newsituation->type=stone[situation->y+1][situation->x].type;
newsituation->next=result;
result=newsituation;
found=1;
noticed[situation->y+1][situation->x]=1;
}
}
//Behind
if (noticed[situation->y][(situation->x+8)%16]==0 &&
stone[situation->y][(situation->x+8)%16].type==type)
{
pwinsituation newsituation=(pwinsituation)malloc(sizeof(twinsituation));
newsituation->x=(situation->x+8)%16;
newsituation->y=situation->y;
newsituation->type=stone[situation->y][(situation->x+8)%16].type;
newsituation->next=result;
result=newsituation;
found=1;
noticed[situation->y][(situation->x+8)%16]=1;
}
situation=situation->next;
}
}
if (type==7)
{
pwinsituation situation=result;
while (situation!=finalresult)
{
if (stone[situation->y][situation->x].type==7)
{
//left
if (noticed[situation->y][(situation->x+15)%16]==0)
{
pwinsituation newsituation=(pwinsituation)malloc(sizeof(twinsituation));
newsituation->x=(situation->x+15)%16;
newsituation->y=situation->y;
newsituation->next=result;
newsituation->type=stone[situation->y][(situation->x+15)%16].type;
result=newsituation;
found=1;
noticed[situation->y][(situation->x+15)%16]=1;
}
//Right
if (noticed[situation->y][(situation->x+1)%16]==0)
{
pwinsituation newsituation=(pwinsituation)malloc(sizeof(twinsituation));
newsituation->x=(situation->x+1)%16;
newsituation->y=situation->y;
newsituation->type=stone[situation->y][(situation->x+1)%16].type;
newsituation->next=result;
result=newsituation;
found=1;
noticed[situation->y][(situation->x+1)%16]=1;
}
//Down
if (situation->y>0)
{
if (noticed[situation->y-1][situation->x]==0)
{
pwinsituation newsituation=(pwinsituation)malloc(sizeof(twinsituation));
newsituation->x=situation->x;
newsituation->y=situation->y-1;
newsituation->type=stone[situation->y-1][situation->x].type;
newsituation->next=result;
result=newsituation;
found=1;
noticed[situation->y-1][situation->x]=1;
}
}
//Up
if (situation->y<6)
{
if (noticed[situation->y+1][situation->x]==0)
{
pwinsituation newsituation=(pwinsituation)malloc(sizeof(twinsituation));
newsituation->x=situation->x;
newsituation->y=situation->y+1;
newsituation->type=stone[situation->y+1][situation->x].type;
newsituation->next=result;
result=newsituation;
found=1;
noticed[situation->y+1][situation->x]=1;
}
}
}
situation=situation->next;
}
}
finalresult = result;
}
}
return finalresult;
}
void delete_win_situation(pwinsituation situation)
{
while (situation!=NULL)
{
pwinsituation temp = situation->next;
free(situation);
situation=temp;
}
}
void remove_win_situations()
{
pwinsituation situation;
while ((situation=search_win_situation())!=NULL)
{
pwinsituation temp=situation;
while (temp!=NULL)
{
if (settings_get_color())
{
if (rand()%LIKELYHOOD < LIKELYHOOD-1)
stone[temp->y][temp->x].type=rand()%6;
else
stone[temp->y][temp->x].type=rand()%3+6;
}
else
{
if (rand()%LIKELYHOOD < LIKELYHOOD-1)
stone[temp->y][temp->x].type=rand()%4;
else
stone[temp->y][temp->x].type=rand()%3+6;
}
stone[temp->y][temp->x].h=get_type_color_h(stone[temp->y][temp->x].type,w);
stone[temp->y][temp->x].s=get_type_color_s(stone[temp->y][temp->x].type,w);
stone[temp->y][temp->x].v=get_type_color_v(stone[temp->y][temp->x].type,w);
temp=temp->next;
}
}
delete_win_situation(situation);
}
void init_light()
{
/*plight light=engineGetLightPointer();
light[0].r=255;
light[0].g=255;
light[0].b=255;*/
}
void prepare_game_objects(char complete)
{
if (!complete)
{
points = 0;
gameTime = START_TIME;
realTime = 0;
chain = 0;
int a,y;
for (y=0;y<7;y++)
for (a=0;a<16;a++)
{
if (settings_get_color())
{
if (rand()%LIKELYHOOD < LIKELYHOOD-1)
stone[y][a].type=rand()%6;
else
stone[y][a].type=rand()%3+6;
}
else
{
if (rand()%LIKELYHOOD < LIKELYHOOD-1)
stone[y][a].type=rand()%4;
else
stone[y][a].type=rand()%3+6;
}
stone[y][a].h=get_type_color_h(stone[y][a].type,w);
stone[y][a].s=get_type_color_s(stone[y][a].type,w);
stone[y][a].v=get_type_color_v(stone[y][a].type,w);
stone[y][a].falling=0;
stone[y][a].new=0;
}
if (settings_get_control() == 1)
{
posx[0]=0;
posy[0]=-2<<SP_ACCURACY;
posx[3]=posx[0];
posy[3]=posy[0];
posx[1]=0;
posy[1]=0;
posx[2]=0;
posy[2]=2<<SP_ACCURACY;
}
else
{
posx[0]=0;
posy[0]=0;
}
int i;
for (i=0;i<2*TIMEOUT;i++)
{
pointposx[i]=0;
pointposy[i]=(i-TIMEOUT<<SP_ACCURACY)/(TIMEOUT/2);
}
is_change=0;
pointstart=0;
timeout=0;
direction=2;
firstchange=NULL;
firstparticle=NULL;
remove_win_situations();
init_light();
delete_all_lettering();
delete_all_bordering();
}
else
{
int i;
char buffer[256];
for (i = 0; i < 9; i++)
{
sprintf(buffer,"./images/stone%i.png",i+1);
stone_texture[i] = spLoadSurface(buffer);
}
for (i = 0; i < 4; i++)
{
sprintf(buffer,"./images/trophy%i.png",i);
trophy_texture[i] = spLoadSurface(buffer);
}
resize_particle(spGetWindowSurface()->w,spGetWindowSurface()->h);
}
}
void delete_game_objects()
{
int i;
for (i = 0;i<9;i++)
SDL_FreeSurface(stone_texture[i]);
for (i = 0;i<4;i++)
SDL_FreeSurface(trophy_texture[i]);
}
void new_particle(Sint32 x,Sint32 y,Sint32 z,Sint32 h,Uint8 s,Uint8 v,Sint32 rotx,Sint32 roty,Sint32 rotz)
{
pparticle particle=(pparticle)malloc(sizeof(tparticle));
particle->x=x;
particle->y=y;
particle->z=z;
particle->h=h;
particle->s=s;
particle->v=v;
particle->rotx=rotx;
particle->roty=roty;
particle->rotz=rotz;
particle->dx=rand()%(1<<SP_ACCURACY-7)-(1<<SP_ACCURACY-8);
particle->dy=rand()%(1<<SP_ACCURACY-7)-(1<<SP_ACCURACY-8);
particle->dz=rand()%(1<<SP_ACCURACY-7)-(1<<SP_ACCURACY-8);
particle->age=PARTICLE_AGE;
particle->next=firstparticle;
firstparticle=particle;
}
void step_particles()
{
pparticle last=NULL;
pparticle particle=firstparticle;
while (particle)
{
particle->dy-=1<<SP_ACCURACY-15;
particle->x+=particle->dx;
particle->y+=particle->dy;
particle->z+=particle->dz;
particle->age--;
if (particle->age<=0)
{
if (last)
last->next=particle->next;
else
firstparticle=particle->next;
free(particle);
particle=last;
}
last=particle;
if (particle)
particle=particle->next;
}
}
void initate_change(int ax,int ay,int bx,int by)
{
pchange newchange=(pchange)malloc(sizeof(tchange));
newchange->progress=CHANGE_TIME;
newchange->ax=ax;
newchange->ay=ay;
newchange->bx=bx;
newchange->by=by;
newchange->next=firstchange;
firstchange=newchange;
}
void step_changes()
{
pchange lastchange=NULL;
pchange change=firstchange;
while (change!=NULL)
{
change->progress--;
if (change->progress==0)
{
tstone temp=stone[change->ay][change->ax];
stone[change->ay][change->ax]=stone[change->by][change->bx];
stone[change->by][change->bx]=temp;
free(change);
if (lastchange==NULL)
firstchange=NULL;
else
lastchange->next=NULL;
break;
}
lastchange=change;
change=change->next;
}
}
pchange is_in_change(int x,int y)
{
pchange change=firstchange;
while (change!=NULL)
{
if (change->ax==x && change->ay==y)
return change;
if (change->bx==x && change->by==y)
return change;
change=change->next;
}
return NULL;
}
void make_win_situations_invalid()
{
spBundlePointer translation = settings_get_translation();
spFontPointer font = settings_get_font();
spFontPointer small_font = settings_get_small_font();
spFontPointer middle_font = settings_get_middle_font();
int new_points = 0;
pwinsituation situation;
char found = 0;
char type_found[12];
while ((situation=search_win_situation())!=NULL)
{
memset(type_found,0,12);
//type_found[6]=1;
char count = 0;
found = 1;
pwinsituation temp=situation;
int i = 0;
while (temp!=NULL)
{
if (stone[temp->y][temp->x].type>=0 && type_found[stone[temp->y][temp->x].type] == 0)
{
printf("__%i__\n",stone[temp->y][temp->x].type);
add_bordering(situation,GET_TYPE_COLOR(stone[temp->y][temp->x].type,w));
count++;
type_found[stone[temp->y][temp->x].type] = 1;
}
stone[temp->y][temp->x].type=-1;
play_explosion();
if (settings_get_particles() == 2)
{
new_particle(spCos((temp->x*SP_PI>>3)-SP_PI/32)*5,((temp->y-3)*2<<SP_ACCURACY)-(1<<SP_ACCURACY-1),spSin((temp->x*SP_PI>>3)-SP_PI/32)*5,
stone[temp->y][temp->x].h,stone[temp->y][temp->x].s,stone[temp->y][temp->x].v,
0,2*SP_PI+SP_PI/2-(temp->x*SP_PI>>3),0);
new_particle(spCos((temp->x*SP_PI>>3)+SP_PI/32)*5,((temp->y-3)*2<<SP_ACCURACY)-(1<<SP_ACCURACY-1),spSin((temp->x*SP_PI>>3)+SP_PI/32)*5,
stone[temp->y][temp->x].h,stone[temp->y][temp->x].s,stone[temp->y][temp->x].v,
0,2*SP_PI+SP_PI/2-(temp->x*SP_PI>>3),0);
new_particle(spCos((temp->x*SP_PI>>3)-SP_PI/32)*5,((temp->y-3)*2<<SP_ACCURACY)+(1<<SP_ACCURACY-1),spSin((temp->x*SP_PI>>3)-SP_PI/32)*5,
stone[temp->y][temp->x].h,stone[temp->y][temp->x].s,stone[temp->y][temp->x].v,
0,2*SP_PI+SP_PI/2-(temp->x*SP_PI>>3),0);
new_particle(spCos((temp->x*SP_PI>>3)+SP_PI/32)*5,((temp->y-3)*2<<SP_ACCURACY)+(1<<SP_ACCURACY-1),spSin((temp->x*SP_PI>>3)+SP_PI/32)*5,
stone[temp->y][temp->x].h,stone[temp->y][temp->x].s,stone[temp->y][temp->x].v,
0,2*SP_PI+SP_PI/2-(temp->x*SP_PI>>3),0);
}
else
if (settings_get_particles() == 1)
{
new_particle(spCos((temp->x*SP_PI>>3))*5,((temp->y-3)*2<<SP_ACCURACY),spSin((temp->x*SP_PI>>3))*5,
stone[temp->y][temp->x].h,stone[temp->y][temp->x].s,stone[temp->y][temp->x].v,
0,2*SP_PI+SP_PI/2-(temp->x*SP_PI>>3),0);
}
i++;
printf("%i:%i with type %i\n",temp->x,temp->y,temp->type);
temp=temp->next;
}
if (i>0)
{
new_points = (int)(pow((float)(i),1.5)*100.0);
char buffer[32];
sprintf(buffer,"+%i (%i)",new_points,i);
add_line();
add_lettering(buffer,small_font);
}
if (i<7)
{}
else
if (i<10)
add_lettering(spGetTranslationFromCaption(translation,"Well!"),middle_font);
else
if (i<14)
add_lettering(spGetTranslationFromCaption(translation,"Great!"),middle_font);
else
if (i<19)
add_lettering(spGetTranslationFromCaption(translation,"Fantastic!"),middle_font);
else
if (i<25)
add_lettering(spGetTranslationFromCaption(translation,"Incredible!"),middle_font);
delete_win_situation(situation);
if (count>1)
{
add_lettering("+15 %",small_font);
add_lettering(spGetTranslationFromCaption(translation,"Combo!"),middle_font);
new_points = new_points * 115/100;
}
}
if (found)
{
chain++;
chain_break=100;
if (chain>1)
{
char buffer[256];
sprintf(buffer,"+%i %%",(chain-1)*10);
add_lettering(buffer,small_font);
switch (chain)
{
case 2: add_lettering(spGetTranslationFromCaption(translation,"Chain!"),middle_font);break;
case 3: add_lettering(spGetTranslationFromCaption(translation,"2x Chain!"),middle_font); break;
case 4: add_lettering(spGetTranslationFromCaption(translation,"3x Chain!"),middle_font); break;
case 5: add_lettering(spGetTranslationFromCaption(translation,"4x Chain!"),middle_font); break;
case 6: add_lettering(spGetTranslationFromCaption(translation,"5x Chain!"),middle_font); break;
default: add_lettering(spGetTranslationFromCaption(translation,"Mega Chain!"),middle_font); break;
}
new_points = new_points * (9+chain) / 10;
}
if (new_points>0)
add_pointVis(new_points);
if (settings_get_mode() == 1)
{
gameTime += new_points*5;
if (gameTime > START_TIME)
gameTime = START_TIME;
}
else
{
points += new_points;
printf("===%i===\n",points);
}
}
}
#define PARTICLE_SPEED 1500
void draw_particle(int posx,int posy,Sint32 r,int time,SDL_Surface* particle)
{
spSetAlphaPattern4x4(PARTICLE_ALPHA,0);
Sint32* modellViewMatrix=spGetMatrix();
Sint32 matrix[16];
memcpy(matrix,modellViewMatrix,sizeof(Sint32)*16);
spTranslate(spCos(-(posx>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1)+SP_PI/2)*22>>2,posy,spSin((posx>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1)+SP_PI/2)*22>>2);
spRotate(0,1<<SP_ACCURACY,0,(posx>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1));
if (time<PARTICLE_SPEED/4)
spBlit3D(r*time/(PARTICLE_SPEED/8)-r,r,0,particle);
else
if (time<PARTICLE_SPEED/2)
spBlit3D(r,r-r*(time-PARTICLE_SPEED/4)/(PARTICLE_SPEED/8),0,particle);
else
if (time<3*PARTICLE_SPEED/4)
spBlit3D(r-r*(time-PARTICLE_SPEED/2)/(PARTICLE_SPEED/8),-r,0,particle);
else
spBlit3D(-r,r-r*(PARTICLE_SPEED-time)/(PARTICLE_SPEED/8),0,particle);
memcpy(modellViewMatrix,matrix,sizeof(Sint32)*16);
spDeactivatePattern();
}
#define PARTICLE_SPEED2 2500
void draw_particle2(int posx,int posy,Sint32 r,int time,SDL_Surface* particle)
{
spSetAlphaPattern4x4(PARTICLE_ALPHA,0);
Sint32* modellViewMatrix=spGetMatrix();
Sint32 matrix[16];
memcpy(matrix,modellViewMatrix,sizeof(Sint32)*16);
spTranslate(spCos(-(posx>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1)+SP_PI/2)*22>>2,posy,spSin((posx>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1)+SP_PI/2)*22>>2);
spRotate(0,1<<SP_ACCURACY,0,(posx>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1));
if (time<PARTICLE_SPEED2/4)
spBlit3D(r-r*time/(PARTICLE_SPEED2/8),r,0,particle);
else
if (time<PARTICLE_SPEED2/2)
spBlit3D(r,r*(time-PARTICLE_SPEED2/4)/(PARTICLE_SPEED2/8)-r,0,particle);
else
if (time<3*PARTICLE_SPEED2/4)
spBlit3D(r*(time-PARTICLE_SPEED2/2)/(PARTICLE_SPEED2/8)-r,-r,0,particle);
else
spBlit3D(-r,r*(PARTICLE_SPEED2-time)/(PARTICLE_SPEED2/8)-r,0,particle);
memcpy(modellViewMatrix,matrix,sizeof(Sint32)*16);
spDeactivatePattern();
}
int last_rotate = 0;
int choose_one = 0; //1 A, 2 B, 3 X, 4 Y
void draw_stone(int type,int h,int s,int v,int a,Sint32 posx_zero,int w, int special)
{
if (special)
{
Uint16 input = spGetHSV(h,s,v);
Uint16 color = spGetHSV(0,0,255-96+(3*spSin((-posx_zero>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1)-((a+8)*SP_PI>>3))>>(SP_ACCURACY-5)));
Uint16 output = ((input * color >> 16) & 63488)
+ (((input & 2047) * (color & 2047) >> 11) & 2016)
+ ((input & 31) * (color & 31) >> 5);
spQuad3D(0,+SP_ONE/2,0,
0,-SP_ONE/2,0,
0,-SP_ONE/8,-SP_ONE*5,
0,+SP_ONE/8,-SP_ONE*5,output);
spQuad3D(+SP_ONE/2,0,0,
-SP_ONE/2,0,0,
-SP_ONE/8,0,-SP_ONE*5,
+SP_ONE/8,0,-SP_ONE*5,output);
}
if (settings_get_stone_quality() == 2)
{
spBindTexture(stone_texture[type]);
spQuadTex3D(-7<<SP_ACCURACY-3,-7<<SP_ACCURACY-3,0,0,stone_texture[0]->h-SP_FONT_EXTRASPACE-1,
7<<SP_ACCURACY-3,-7<<SP_ACCURACY-3,0,stone_texture[0]->w-SP_FONT_EXTRASPACE-1,stone_texture[0]->h-SP_FONT_EXTRASPACE-1,
7<<SP_ACCURACY-3, 7<<SP_ACCURACY-3,0,stone_texture[0]->w-SP_FONT_EXTRASPACE-1,0,
-7<<SP_ACCURACY-3, 7<<SP_ACCURACY-3,0,0,0,spGetHSV(0,0,255-64+(2*spSin((-posx_zero>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1)-((a+8)*SP_PI>>3))>>(SP_ACCURACY-5))));
}
else
if (settings_get_stone_quality() == 1)
{
Uint16 input = spGetHSV(h,s,v);
Uint16 color = spGetHSV(0,0,255-96+(3*spSin((-posx_zero>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1)-((a+8)*SP_PI>>3))>>(SP_ACCURACY-5)));
Uint16 output = ((input * color >> 16) & 63488)
+ (((input & 2047) * (color & 2047) >> 11) & 2016)
+ ((input & 31) * (color & 31) >> 5);
input = spGetHSV(h,s*3/4,v);
Uint16 lighter = ((input * color >> 16) & 63488)
+ (((input & 2047) * (color & 2047) >> 11) & 2016)
+ ((input & 31) * (color & 31) >> 5);
input = spGetHSV(h,s,v*3/4);
Uint16 dark = ((input * color >> 16) & 63488)
+ (((input & 2047) * (color & 2047) >> 11) & 2016)
+ ((input & 31) * (color & 31) >> 5);
input = spGetHSV(h,s,v*2/4);
Uint16 darker = ((input * color >> 16) & 63488)
+ (((input & 2047) * (color & 2047) >> 11) & 2016)
+ ((input & 31) * (color & 31) >> 5);
spQuad3D(-5<<SP_ACCURACY-3,-5<<SP_ACCURACY-3,0,
5<<SP_ACCURACY-3,-5<<SP_ACCURACY-3,0,
5<<SP_ACCURACY-3, 5<<SP_ACCURACY-3,0,
-5<<SP_ACCURACY-3, 5<<SP_ACCURACY-3,0,output);
spQuad3D(-7<<SP_ACCURACY-3,-7<<SP_ACCURACY-3,0,
-5<<SP_ACCURACY-3,-5<<SP_ACCURACY-3,0,
-5<<SP_ACCURACY-3, 5<<SP_ACCURACY-3,0,
-7<<SP_ACCURACY-3, 7<<SP_ACCURACY-3,0,dark);
spQuad3D( 7<<SP_ACCURACY-3,-7<<SP_ACCURACY-3,0,
5<<SP_ACCURACY-3,-5<<SP_ACCURACY-3,0,
5<<SP_ACCURACY-3, 5<<SP_ACCURACY-3,0,
7<<SP_ACCURACY-3, 7<<SP_ACCURACY-3,0,dark);
spQuad3D(-7<<SP_ACCURACY-3,-7<<SP_ACCURACY-3,0,
7<<SP_ACCURACY-3,-7<<SP_ACCURACY-3,0,
5<<SP_ACCURACY-3,-5<<SP_ACCURACY-3,0,
-5<<SP_ACCURACY-3,-5<<SP_ACCURACY-3,0,darker);
spQuad3D(-7<<SP_ACCURACY-3, 7<<SP_ACCURACY-3,0,
7<<SP_ACCURACY-3, 7<<SP_ACCURACY-3,0,
5<<SP_ACCURACY-3, 5<<SP_ACCURACY-3,0,
-5<<SP_ACCURACY-3, 5<<SP_ACCURACY-3,0,lighter);
}
else
{
Uint16 input = spGetHSV(h,s,v);
Uint16 color = spGetHSV(0,0,255-96+(3*spSin((-posx_zero>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1)-((a+8)*SP_PI>>3))>>(SP_ACCURACY-5)));
Uint16 output = ((input * color >> 16) & 63488)
+ (((input & 2047) * (color & 2047) >> 11) & 2016)
+ ((input & 31) * (color & 31) >> 5);
spQuad3D(-7<<SP_ACCURACY-3,-7<<SP_ACCURACY-3,0,
7<<SP_ACCURACY-3,-7<<SP_ACCURACY-3,0,
7<<SP_ACCURACY-3, 7<<SP_ACCURACY-3,0,
-7<<SP_ACCURACY-3, 7<<SP_ACCURACY-3,0,output);
}
}
void draw_game(void)
{
spBundlePointer translation = settings_get_translation();
if (settings_get_stone_quality() != 2)
spSetAlphaTest(0);
spFontPointer font = settings_get_font();
spFontPointer small_font = settings_get_small_font();
spFontPointer middle_font = settings_get_middle_font();
spFontPointer countdown_font = settings_get_countdown_font();
spFontPointer highscore_font = settings_get_highscore_font();
SDL_Surface* screen = spGetWindowSurface();
Sint32* modellViewMatrix=spGetMatrix();
//plight light=engineGetLightPointer();
int engineWindowX=spGetWindowSurface()->w;
int engineWindowY=spGetWindowSurface()->h;
//spResetZBuffer();
spIdentity();
Sint32 matrix[16];
spTranslate(0,0,-20<<SP_ACCURACY);
if (settings_get_stars_rotating()==0)
spClearTarget(BACKGROUND_COLOR);
//Stars
spSetZSet(0);
spSetZTest(0);
if (settings_get_stars_rotating()==1)
draw_stars(star_add);
else
if (settings_get_stars_rotating()==2)
draw_stars((-posx[0]>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1)+star_add);
spRotate(0,1<<SP_ACCURACY,0,(-posx[0]>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1));
last_rotate = (-posx[0]>>SP_HALF_ACCURACY+2)*(SP_PI>>SP_HALF_ACCURACY+1);
int add=1;
if (is_change>0)
{
if (is_change<2)
add++;
spRotate(0,-1<<SP_ACCURACY,0,((timeout<<SP_HALF_ACCURACY-1)/TIMEOUT)*(SP_PI>>SP_HALF_ACCURACY+add));
last_rotate += ((timeout<<SP_HALF_ACCURACY-1)/TIMEOUT)*(SP_PI>>SP_HALF_ACCURACY+add);
}
if (is_change<0)
{
if (is_change>-2)
add++;
spRotate(0, 1<<SP_ACCURACY,0,((timeout<<SP_HALF_ACCURACY-1)/TIMEOUT)*(SP_PI>>SP_HALF_ACCURACY+add));
last_rotate += ((timeout<<SP_HALF_ACCURACY-1)/TIMEOUT)*(SP_PI>>SP_HALF_ACCURACY+add);
}
//spTranslate(0,spSin(w<<3)>>2,0);
spRotate(1<<SP_ACCURACY,0,0,(spSin(w<<3)>>SP_HALF_ACCURACY)*(SP_PI>>SP_HALF_ACCURACY)>>5);
spRotate(0,1<<SP_ACCURACY,0,(spCos(w<<3)>>SP_HALF_ACCURACY)*(SP_PI>>SP_HALF_ACCURACY)>>5);
int meta_a,a,y;
//Drawing from the back to the front
spSetZTest(0);
spSetZSet(0);
int left_side = 1;
//for (meta_a=16-(posx[0]>>SP_ACCURACY)+15;meta_a>=16-(posx[0]>>SP_ACCURACY);meta_a--)
meta_a=16-(posx[0]+SP_ONE/2>>SP_ACCURACY)+12; //back
int left_a = meta_a;
int right_a = meta_a;
int i;
for (i = 0; i < 16; i++)
{
a = meta_a & 15;
int loop_y;
for (loop_y = 0; loop_y < 7; loop_y++)
//for (y=-6;y<=6;y+=2)
{
switch (loop_y)
{
case 0: y = -6; break;
case 1: y = +6; break;
case 2: y = -4; break;
case 3: y = +4; break;
case 4: y = -2; break;
case 5: y = +2; break;
case 6: y = 0; break;
}
memcpy(matrix,modellViewMatrix,sizeof(Sint32)*16);
pchange change=is_in_change(a,3+y/2);
Sint32 px=spCos(a*SP_PI>>3)*5;
Sint32 py=y<<SP_ACCURACY;
Sint32 pz=spSin(a*SP_PI>>3)*5;
if (change)
{
int sign=1;
Sint32 new_a=a<<SP_ACCURACY;
Sint32 new_y=y<<SP_ACCURACY;
if (change->bx==a && change->by==3+y/2)
sign=-1;
switch (change->ax-change->bx)
{
case 14:
case - 2: new_a+=sign*2*((CHANGE_TIME-change->progress)<<SP_ACCURACY)/CHANGE_TIME; break;
case 15:
case - 1: new_a+=sign* ((CHANGE_TIME-change->progress)<<SP_ACCURACY)/CHANGE_TIME; break;
case -15:
case 1: new_a-=sign* ((CHANGE_TIME-change->progress)<<SP_ACCURACY)/CHANGE_TIME; break;
case -14:
case 2: new_a-=sign*2*((CHANGE_TIME-change->progress)<<SP_ACCURACY)/CHANGE_TIME; break;
}
switch (change->ay-change->by)
{
case -2: new_y+=sign*4*((CHANGE_TIME-change->progress)<<SP_ACCURACY)/CHANGE_TIME; break;
case -1: new_y+=sign*2*((CHANGE_TIME-change->progress)<<SP_ACCURACY)/CHANGE_TIME; break;
case 1: new_y-=sign*2*((CHANGE_TIME-change->progress)<<SP_ACCURACY)/CHANGE_TIME; break;