-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c~
3019 lines (2648 loc) · 44.1 KB
/
main.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
/*
Progammed in pure C by piccahoe aka near
For Multipile systems -- Linux,PSP and Windows
============= Compiling: ==================
Extract the folders and files.
Linux (compiled on Ubuntu)
1. You must have OpenGL, SDL, SDL_TIFF and SDL_mix (you can do an apt-get if you have unbuntu)
2. Open the folder you extract thats named blockheadU
3. Open the folder named linux
4. Click on gcc_compile to compile it in C or g++_compile to compile it in C+++
5. if #ifdef _SDL is comment out, uncomment it and if #ifdef _psp is not commented out then comment it out
6. in main.c if #ifdef _SDL is comment out, uncomment it and if #ifdef _psp is not commented out then comment it out
Windows (compile on XP with Dev C++)
1. You must have Dev C++, SDL (with SDL Font and SDL_mixer)
2. Open up dev C++ and open up the project in the folder /blockheadU/windows
3. Add the ../mysdl/timer.h ../mysdl/timer.cpp ../mysdl/sdls.h ../mysdl/sdls.cpp -lmingw32 -lSDLmain -lSDL -lSDL_ttf (goto project, then project option, then go to parameter)
4. if you see main.o with main.c, delete it
5. in main.c if #ifdef _SDL is comment out, uncomment it and if #ifdef _psp is not commented out then comment it out
(You might be able to compile it in cywin also)
PSP
1. You must have the pspsdk and png installed.
2. In main.c, look for #ifdef _PSP and if its commented out uncomment it and if #ifdef _SDL is not commented out then commented it out.
3. Go to the prompt go to the psp folder /blockheadU/PSP and type make.
======================= Things to do: ===========================
1. Fix normal -> wide in game option (psp)
2. Fix Text position (psp)
3. Add music and sound (psp)
4. Add Top scoreboard
*/
#define _nds
//#define _psp
//#define _SDL
#include <string.h>
#include <malloc.h>
#ifdef _psp
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <png.h>
#include "PSP/graphics.h"
#endif
#ifdef _SDL
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_mixer.h"
#include <time.h>
#include "mysdl/sdls.h"
#endif
#ifdef _nds
#include <nds.h>
#include <stdio.h>
#endif
#ifdef _linux
#include <pthread.h>
#endif
#ifdef _psp
#define printf pspDebugScreenPrintf
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
#define RGB(r, g, b) ((r)|((g)<<8)|((b)<<16))
PSP_MODULE_INFO("Block Head 1.0", 0, 1, 1);
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
#endif
struct piece
{
int size[5][5];
int x;
int y;
int mapx;
int mapy;
int isdown;
int ishitright;
int ishitleft;
int bottom;
int top;
int right;
int left;
int r;
int g;
int b;
int num;
};
/*varibles*/
#ifdef _psp
int MAPWIDTH=11;
int MAPHEIGHT=26;
int Map[30][27];
#endif
#ifdef _SDL
//Timer fps;
/*==============For timer ===== */
int startTicks;
int pausedTicks;
int paused;
int started;
const int FRAMES_PER_SECOND = 25;
const int SCREEN_BPP = 32;
int MAPWIDTH=9;
int MAPHEIGHT=26;
const int SCREEN_WIDTH = 300;
const int SCREEN_HEIGHT = 400;
int Map[30][26];
#endif
#ifdef _nds
int MAPWIDTH=12;
int MAPHEIGHT=22;
int Map[32][22];
#endif
char xytxt1[255];
int quit = 0;
int gamestarted= 0;
int frame = 0;
int gamestate=1;
int isdown=0;
int canmove = 1;
int level=1;
int tamez=0;
int j=0;
int temp[4][4];
enum { title_screen,gameplay,gameover,options,pauseit,aboutscr };
struct piece spiece;
struct piece npiece;
int downtime=0;
int isdowntime=0;
int lvltme=0;
int islvltme=0;
int isrotin = 0;
int isunder=0;
int blkdwn=0;
int islrspeed=0;
int lrspeed=0;
int score=0;
int levelup=0;
#ifdef _psp
int blockspeed=30;
#endif
#ifdef _SDL
int blockspeed=15;
#endif
#ifdef _nds
int blockspeed=30;
#endif
#ifdef _psp
int lrspeedtotal=8;
#endif
#ifdef _SDL
int lrspeedtotal=2;
#endif
#ifdef _nds
int lrspeedtotal=8;
#endif
int nextblock=-1;
int gmeovrtmr=0;
#ifdef _psp
int ttldwntme = 35;
#endif
#ifdef _SDL
int ttldwntme = 15;
#endif
#ifdef _nds
int ttldwntme = 35;
#endif
#ifdef _psp
int blocksize=10; //shrink the blocks to fit the psp screen
int pblocksize=8;
#endif
#ifdef _SDL
int blocksize=16;
int pblocksize=14;
#endif
#ifdef _nds
int blocksize=8;
int pblocksize=8;
#endif
int menutimer=0;
#ifdef _SDL
int ttlmnutme=3;
#endif
#ifdef _psp
int ttlmnutme=10;
#endif
#ifdef _nds
int ttlmnutme=10;
#endif
int ismenutt=0;
#ifdef _SDL
int menucursy=165;
#endif
#ifdef _psp
int menucursy=100;
#endif
#ifdef _nds
int menucursy=100;
#endif
int omenutimer=0;
#ifdef _SDL
int ottlmnutme=3;
#endif
#ifdef _psp
int ottlmnutme=10;
#endif
#ifdef _nds
int ottlmnutme=10;
#endif
int oismenutt=0;
int omenucursy=125;
enum { normal,wide };
int fldsze=normal;
int ispause=0;
int ispauset=0;
int gpausec=0;
#ifdef _SDL
int gpausett=3;
#endif
#ifdef _psp
int gpausett=10;
#endif
#ifdef _nds
int gpausett=10;
#endif
#ifdef _SDL
int gmnuy=145;
#endif
#ifdef _psp
int gmnuy=60;
#endif
#ifdef _nds
int gmnuy=60;
#endif
#ifdef _SDL
int gmnux=80;
#endif
#ifdef _psp
int gmnux=160;
#endif
#ifdef _nds
int gmnux=160;
#endif
int mispause=0;
int mpausec=0;
#ifdef _SDL
int mpausett=3;
#endif
#ifdef _psp
int mpausett=10;
#endif
#ifdef _nds
int mpausett=10;
#endif
int ispause2=0;
int ispauset2=0;
int gpausec2=0;
#ifdef _SDL
int gpausett2=3;
#endif
#ifdef _psp
int gpausett2=10;
#endif
#ifdef _nds
int gpausett2=10;
#endif
#ifdef _SDL
int gmnuy2=145;
#endif
#ifdef _psp
int gmnuy2=100;
#endif
#ifdef _nds
int gmnuy2=100;
#endif
#ifdef _SDL
int gmnux2=80;
#endif
#ifdef _psp
int gmnux2=160;
#endif
#ifdef _nds
int gmnux2=160;
#endif
int mispause2=0;
int mpausec2=0;
#ifdef _SDL
int mpausett2=3;
#endif
#ifdef _psp
int mpausett2=10;
#endif
#ifdef _nds
int mpausett2=10;
#endif
#ifdef _nds
u16* bkblk;
u16* gfx;
u16* gfxSub;
uint16 keysPressed;
uint16 specialKeysPressed;
int blockid=0;
int screen = 1;
#endif
int (*fun2exe)();
int bonus=0;
int ttlbnus=0;
int isbnustrig=0;
int tbispause=0;
int tbpausec=0;
int tbpausett=30;
char ttlbnuss[255];
int isabout=0;
int ismusic=1;
int titlex=0,titley=0;
int blksptx=0,blkspty=0;
int sgamex=0,sgamey=0;
int ogamex=0,ogamey=0;
int agamex=0,agamey=0;
int egamex=0,egamey=0;
int gameopx=0;
int gameopy=0;
int gameopsndx=0;
int gameopsndy=0;
int gameopmusx=0;
int gameopmusy=0;
int gameopex = 0;
int gameopey=0;
int gameopftx=0;
int gameopfty=0;
int recx=0;
int recy=0;
int recw=0;
int rech=0;
int sndonx=0;
int sndony=0;
int fldszex=0;
int fldszey=0;
int sndeffx=0;
int sndeffy=0;
int gmepx=0;
int gmepy=0;
int gpconx=0;
int gpcony=0;
int gpopx=0;
int gpopy=0;
int gpexy=0;
int gpexx=0;
int olvlsrtx=0;
int olvlsrty=0;
int blockids=0;
enum { gmepmenu, gmepomenu };
int gameoption=gmepmenu;
/*
Graphic engine varibles
*/
#ifdef _psp
SceCtrlData pad;
#endif
#ifdef _nds
uint16 keysPressed;
uint16 specialKeysPressed;
int bg;
u16 colorMask;
u16* backBuffer;
uint16* back = VRAM_A;
uint16* front = VRAM_B;
#endif
#ifdef _SDL
SDL_Event event;
SDL_Surface *screen = NULL;
TTF_Font *font = NULL;
TTF_Font *titlefont = NULL;
SDL_Rect tf;
SDL_Rect paintbg;
SDL_Rect object;
SDL_Color txtcolor = { 255,255,255 };
SDL_Surface *xytetris=NULL;
Uint32 bgcolor;
Uint32 black;
Uint32 objcolor;
Uint8 *keystates;
Mix_Music *music = NULL;
Mix_Chunk *gmeovrsnd = NULL;
#endif
/* functions */
void drawfield();
void clearmap();
void Newblock();
int cotecleft();
int rotatecheckL();
int cotecright();
int rotatecheckD();
int checkdown();
int rstdwntme();
int clrtmp();
int chklne();
int ablock(struct piece* spiece,int newblock);
int chkblkdwn();
int movblkdwn();
int isgmeovr();
int fillmap();
int inigame();
int loadfonts();
int pntscrblk();
int titlescr();
int gameoverscr();
int gp_speed_down();
int gp_rotateblock();
int gp_rotateblock2();
int gp_moveblockl();
int gp_moveblockr();
int gp_lrtimer();
int drawpieces();
int drawmap();
int drawnext();
int printscore();
#ifdef _SDL
int free_();
#endif
int clear_pieces();
int restgame();
int optionscr();
int gooptions();
int ch2gmeop();
int drwnm2wde();
int resetvar();
int aboutbh();
#ifdef _SDL
void start();
void stop();
void pause();
void unpause();
#endif
#ifdef _nds
int drawrec(int id,void *gfxSub,int width,int height, int pos_x,int pos_y, int r,int g,int b);
#endif
//Gets the timer's time
int get_ticks();
//Checks the status of the timer
int is_started();
int is_paused();
int ini_timer();
//graphic engine functions
int iniGraphic();
int framerate();
int frameflip();
int frameloop();
int getkeystate();
int keydownpressed();
int krotateL();
int krotateR();
int keyuppressed();
int keyleftpressed();
int keyrightpressed();
int keyenterpressed();
int keypausepressed();
int g_print(char* msg,int x,int y);
int FillRec(int width,int height,int x, int y,int r, int b, int g);
int main( int argc, char* args[] )
{
inigame();
while( quit == 0 )
{
framerate();
pntscrblk();
getkeystate();
switch(gamestate)
{
case title_screen:
{
titlescr();
break;
}
case gameover:
{
gameoverscr();
break;
}
case gameplay:
{
if (ispause == 0)
{
if (isbnustrig == 1)
{
tbpausec++;
sprintf(ttlbnuss,"Bonus %ix!",ttlbnus);
#ifdef _nds
iprintf("\x1b[12;20H%s",ttlbnuss);
#else
g_print(ttlbnuss,170,175);
#endif
if (tbpausec == tbpausett)
{
isbnustrig = 0;
tbispause=0;
tbpausec=0;
ttlbnus=0;
}
}
blkdwn=0;
chkblkdwn();
if (blkdwn == 1)
{
isdowntime=1;
} else {
movblkdwn();
}
if (isdowntime == 1)
{
if (checkdown() == 1)
{
rstdwntme();
} else {
downtime++;
if (downtime == ttldwntme)
{
downtime=0;
isdowntime=0;
fillmap();
chklne();
if (isgmeovr() == 1)
{
break;
}
Newblock();
}
}
}
if (keydownpressed() && islrspeed == 1)
{
gp_speed_down();
}
if (krotateL() && islrspeed == 1)
{
gp_rotateblock();
}
if (krotateR() && islrspeed == 1)
{
gp_rotateblock2();
}
if (keyleftpressed() && islrspeed == 1)
{
gp_moveblockl();
}
if (keyrightpressed() && islrspeed == 1)
{
gp_moveblockr();
}
}
/*
if ( keypausepressed() == 1 && islrspeed == 1)
{
if (ispause == 0)
{
ispause = 1;
}
}
*/
gp_lrtimer();
drawpieces(); //draws pieces on the map
drawmap();
drawnext();
printscore();
if (ispause == 1)
{
FillRec(recw,rech,recx,recy, 0,0, 255);
switch(gameoption)
{
case gmepomenu:
{
#ifdef _nds
#else
g_print("Game Options",gameopx,gameopy);
g_print("Sound ",gameopsndx,gameopsndy);
g_print("Music ",gameopmusx,gameopmusy);
g_print("Field type ",gameopftx,gameopfty);
g_print("Exit",gameopex,gameopey);
g_print("off",sndeffx,sndeffy);
#endif
if (ismusic==1)
{
#ifdef _SDL
if( Mix_PlayingMusic() == 0 )
{
if( Mix_PlayMusic( music, -1 ) == -1 )
{
ismusic=0;
}
}
#endif
#ifdef _nds
#else
g_print("On",sndonx,sndony);
#endif
} else {
#ifdef _SDL
Mix_HaltMusic();
#endif
#ifdef _nds
g_print("Off",sndonx,sndony);
#endif
}
switch(fldsze)
{
case normal:
{
#ifdef _nds
#else
g_print("normal",fldszex,fldszey);
#endif
break;
}
case wide:
{
#ifdef _nds
g_print("wide",fldszex,fldszey);
#else
#endif
break;
}
}
#ifdef _nds
#else
g_print(">",gmnux2,gmnuy2);
#endif
if (ispauset2==0)
{
gpausec2++;
} else {
ispauset2=0;
gpausec2=0;
}
if (gpausec2 == gpausett2)
{
ispauset2 = 1;
}
if (keydownpressed() && ispauset2 == 1 && gmnuy2 !=gameopey)
{
gmnuy2+=20;
}
if (keyuppressed() && ispauset2 == 1 && gmnuy2 !=gameopsndy)
{
gmnuy2-=20;
}
if (keyleftpressed() && ispauset2 == 1)
{
if (gmnuy2 == gameopmusy)
{
if (ismusic == 1)
{
ismusic=0;
} else {
ismusic=1;
}
}
if (gmnuy2 == gameopfty)
{
if (fldsze == normal)
{
fldsze = wide;
#ifdef _SDL
MAPWIDTH=12;
#endif
#ifdef _psp
MAPWIDTH=14;
#endif
drwnm2wde();
//clearmap();
//drawfield();
} else
if (fldsze == wide)
{
#ifdef _SDL
MAPWIDTH=9;
#endif
#ifdef _psp
MAPWIDTH=11;
#endif
fldsze = normal;
resetvar();
Newblock();
}
}
}
if (keyenterpressed() == 1)
{
if (gmnuy2 == gameopey)
{
#ifdef _SDL
gmnuy2=145;
#endif
#ifdef _psp
gmnuy2=100;
#endif
gameoption=gmepmenu;
}
}
break;
}
case gmepmenu:
{
#ifdef _nds
#else
g_print("Game Paused!",gmepx,gmepy);
g_print("Continue",gpconx,gpcony);
g_print("Options",gpopx,gpopy);
g_print("Exit",gpexx,gpexy);
g_print(">",gmnux,gmnuy);
#endif
if (ispauset==0)
{
gpausec++;
} else {
ispauset=0;
gpausec=0;
}
if (gpausec == gpausett)
{
ispauset = 1;
}
if (keydownpressed() && ispauset == 1 && gmnuy != gpexy)
{
gmnuy+=20;
}
if (keyuppressed() && ispauset == 1 && gmnuy != gpcony)
{
gmnuy-=20;
}
if ( keyenterpressed() && ispauset == 1)
{
if (gmnuy == gpopy)
{
//gameoption=gmepomenu;
gamestate=pauseit;
fun2exe=&ch2gmeop;
}
if (gmnuy == gpcony)
{
ispause=0;
}
if (gmnuy == gpexy)
{
gamestate = pauseit;
fun2exe=&restgame;
break;
}
}
break;
}
}
}
break;
}
case options:
{
optionscr();
break;
}
case aboutscr:
{
aboutbh();
break;
}
case pauseit:
{
if (mispause==0)
{
mpausec++;
} else {
mispause=0;
mpausec=0;
}
if (mpausec == mpausett)
{
mispause = 1;
(*fun2exe)();
}
break;
}
}
frame++;
if (frameflip() == 0)
{
return 1;
}
frameloop();
}
#ifdef _SDL
free_();
#endif
#ifdef _psp
sceKernelExitGame();
#endif
return 0;
}
void drawfield()
{
int t=0;
#ifdef _nds
for (t=1;t<MAPHEIGHT;t++)
{
Map[0][t] = 2;
Map[MAPWIDTH-1][t] = 2;
}
for (t=0;t<MAPWIDTH-1;t++)
{
Map[t][MAPHEIGHT-1] = 3;
}
#endif
#ifdef _psp
for (t=1;t<MAPHEIGHT;t++)
{
Map[0][t] = 2;
Map[MAPWIDTH-1][t] = 2;
}
for (t=0;t<MAPWIDTH-1;t++)
{
Map[t][MAPHEIGHT-1] = 3;
}
#endif
#ifdef _SDL
for (t=1;t<23;t++)
{
Map[0][t] = 2;
Map[MAPWIDTH-1][t] = 2;
}
for (t=0;t<MAPWIDTH;t++)
{
Map[t][23] = 3;
}
#endif
}
void clearmap()
{
int xy=0;
int xy2=0;
for (xy=0;xy<MAPWIDTH;xy++)
{
for (xy2=0;xy2<MAPHEIGHT;xy2++)
{