-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex.c
More file actions
2193 lines (1804 loc) · 60.9 KB
/
ex.c
File metadata and controls
2193 lines (1804 loc) · 60.9 KB
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
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <conio.h>
#include <stdlib.h>
#include "gameboard.h"
#include <process.h>// 멀티스레드 처리 추가
// 사운드 추가1
#include <mmsystem.h>
#pragma comment(lib,"winmm.lib")
// 메인 브금
#define BGM_MAIN1 "sound/questiion_lost moons-greatful eights.wav"
#define BGM_MAIN2 "sound/questiion_lost moons-serious as an attack button.wav"
#define BGM_MAIN3 "sound/zagi2_bodenhacke loop.wav"
// 블랙홀 브금
#define BGM_BLACKHOLE "sound/zagi2_space serpent.wav"
// 엔딩 브금
// 사운드 추가1 끝
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
#define SPACE 32
#define CTRL 17
/*게임보드 크기*/
#define GBOARD_WIDTH 70
#define GBOARD_HEIGHT 50
/*게임보드 시작점*/
#define GBOARD_ORIGIN_X 4
#define GBOARD_ORIGIN_Y 2
/*중력의 방향*/
#define GUP 0
#define GRIGHT 1
#define GDOWN 2
#define GLEFT 3
char blockModel[][3][3] =
{
/* 플레이어
◎ 97
△ 98
∥ 99
= ▷ ◎
-67 -71 97
◎ ◁ =
-73
∥ 99
▽-28
◎ 97
*/
//플레이어의 머리 부분이 중력의 방향
//중력이 위쪽으로 작용할때 0
{
{0, 99, 0 },
{0, 98, 0 },
{0, 97, 0 },
}
,
//중력이 오른쪽으로 작용할때 1
{
{0, 0, 0 },
{97,-71,-67},
{0, 0, 0 },
}
,
//중력이 아래쪽으로 작용할때 2
{
{0, 97, 0 },
{0, -28, 0 },
{0, 99, 0 },
}
,
//중력이 왼쪽으로 작용할때 3
{
{0, 0, 0 },
{-67,-73,97},
{0, 0, 0 },
}
};
int curPosX = 0, curPosY = 0;
int block_id; //현재 PC모습
int speed; //속도
int score = 0; //점수 ?
int mission;
int gravity = 0; //중력방향
int health = 3; //체력
clock_t start, end; //시간
int duration;
int min;
int sec;
int detX, detY;//벽에 붙어있을 경우 옮겨주기 위함
int succ = 0; //스테이지 클리어 여부
int clearflag = 0;// 가시를 안보이게 할지 보이게 할지 결정
int periodflag = 0;//투명가시 on/off 용
int obstacleSpeed = 0; //운석 이동 제어
int isBlackhole = 0; //블랙홀 상태
int mapNum = 1; //스테이지를 나타내는 변수
int tempmapNum; //블랙홀 상태일 때 현 스테이지를 임시저장
int stageKey[10] = { 0,0,0,2,3,3,0,0,0,0 };// 스테이지별 키 개수 조정 가능
int acheivecnt = 0;
int In4Min = 0; // 4분 이내로 클리어
int In3Life = 0; // 목숨 3개로 클리어
int InNoBlackHole = 0; // 블랙홀에 한번도 안빠지고 클리어
int InProgamer = 0; // 4분 이내에 3개 목숨으로 클리어
int InDrank1Life = 0; // 목숨 1개남고 D랭크로 클리어
int InStage1clear = 0; //스테이지 1 클리어
int InStage4clear = 0; //스테이지 4 클리어
int InStage5clear = 0; //스테이지 5 클리어
int InBlackHoleAddict = 0; //블랙홀 3번 이상 클리어
int InExplorer = 0; // D랭크 + 블랙홀 3번 이상 클리어
int isObstacleCollision = 0; //운석과 충돌 여부
int slowSpeedTime = 0; //PC속도 저하시간 제어
int gravitytemp = 0;
void SetCurrentCursorPos(int x, int y); //커서설정
COORD GetCurrentCursorPos(void);//현재커서 가져오기
void RemoveCursor(void);//커서지우기
void GameInfoInit(); //게임info 초기화
void GameInfoUpdate(); //게임info 업데이트
void DrawMap(); //맵그리기
void ShowBlock(char blockInfo[3][3]); //PC출력
void DeleteBlock(char blockInfo[3][3]); //PC지우기
int DetectCollision(int posX, int posY, char blockModel[3][3]); //PC와 NPC충돌 체크
void CollisionThorn(); //가시와 충돌처리
void RedrawBlocks(char blockInfo[3][3]); //맵 다시 그리기
int ShiftRight(); //중력방향 오른쪽
int ShiftLeft(); //왼쪽
int ShiftUp(); //위
int ShiftDown(); //아래
int IsGameOver(); //게임 종료 체크
void RotateBlock(); //PC회전
int ProcessKeyInput(); //key입력받기
void InitialScreen(); //초기 시작화면
void SecondScreen(); //게임설명 및 방법 화면
void GameFinishScreen(); //게임 종료화면
void moveObstacle(); //운석이동
void CollisionBlackhole(); //블랙홀 처리
int CollisionDest(); //목적지 충돌
void ClearThorn();//투명가시 조절
void CollisionPotion();//포션 발동
void CollisionMeteorite(int x, int y); //운석 충돌
void CollisionKey(); //키 충돌
void drawBar();//중력바
void deleteBar();//중력바 제거
COORD pcStartPos[5] = {
{6,37}, // 0: blackhole
{7,5}, // 1: map 1
{11,25}, // 2: map 2
{13,40}, // 3: map 3
{3,3}, // 4: map 4
};
unsigned _stdcall Thread_A(void* arg)//투명가시 주기 카운팅을 위한 스레드a
{
while (1)
{
Sleep(3000);//3초 지나면
periodflag = 1;
}
}
int main()
{
speed = 10;
SetConsoleTitle(TEXT("Escape From Gravity"));
system("mode con: cols=186 lines=54");
RemoveCursor();
// 사운드 추가2
PlaySound(TEXT(BGM_MAIN3), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
// 사운드 추가2 끝
//화면 구현부
InitialScreen();
SecondScreen();
// 사운드 추가3
PlaySound(TEXT(BGM_MAIN2), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
// 사운드 추가3
//succ = 1;
//succ = -1;
//GameFinishScreen();
//플레이어 위치 및 중력(임시 1스테이지용)
gravity = 2;
block_id = 2;
curPosX = pcStartPos[mapNum].X * 2;
curPosY = pcStartPos[mapNum].Y;
SetCurrentCursorPos(curPosX, curPosY);
_beginthreadex(NULL, 0, Thread_A, 0, 0, NULL);//스레드a 시작
while (1)
{
start = clock();
DrawMap();
drawBar();
GameInfoInit();
//테스트를 위해서 게임종료 적용 X
while (!IsGameOver())
{
ProcessKeyInput();
GameInfoUpdate();
switch (gravity)
{
case GDOWN: //2
ShiftDown();
break;
case GRIGHT: //1
ShiftRight();
break;
case GUP: //0
ShiftUp();
break;
case GLEFT: //3
ShiftLeft();
break;
}
//투명가시
if (periodflag == 1) {
ClearThorn();
periodflag = 0;
}
RedrawBlocks(blockModel[block_id]);
//나머지연산은 운석의 속도를 제어
//스테이지 2 ~ 운석 존재
if (obstacleSpeed % 3 == 0 && mapNum >= 2)
{
obstacleSpeed = 0;
moveObstacle(); //운석 이동
}
//운석과 충돌이후 속도저하 해제
//나머지 연산을 통해 속도저하 시간 제어
if (isObstacleCollision == 1 && slowSpeedTime % 5 == 0) {
speed = 5;
isObstacleCollision = 0;
slowSpeedTime = 0;
}
obstacleSpeed++;
slowSpeedTime++;
end = clock();
if (IsGameOver()) {
break;
}
}
break;
}
GameFinishScreen();
getchar();
return 0;
}
void SetCurrentCursorPos(int x, int y)
{
COORD pos = { x,y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
COORD GetCurrentCursorPos(void)
{
COORD curPoint;
CONSOLE_SCREEN_BUFFER_INFO curInfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curInfo);
curPoint.X = curInfo.dwCursorPosition.X;
curPoint.Y = curInfo.dwCursorPosition.Y;
return curPoint;
}
void RemoveCursor(void)
{
CONSOLE_CURSOR_INFO curInfo;
GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curInfo);
curInfo.bVisible = 0;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &curInfo);
}
// 투명가시 함수 추가
void ClearThorn() {
COORD temp = GetCurrentCursorPos();
int collision;
if (clearflag == 0) {
for (int y = 0; y < GBOARD_HEIGHT; y++) {
for (int x = 0; x < GBOARD_WIDTH; x++) {
if (mapInfo[mapNum][y][x] == 7) {// 투명가시의 위치를 찾고 지워준 다음 맵 정보를 -7로 바꿈
SetCurrentCursorPos(GBOARD_ORIGIN_X + x * 2, GBOARD_ORIGIN_Y + y);
mapInfo[mapNum][y][x] = -7;
printf(" ");
}
}
}
clearflag = 1;// 다음 차례가 가시를 보여줄 차례라는 것을 알려줌
}
else if (clearflag == 1) {
int flag = 0;
collision = 0;
for (int y = 0; y < GBOARD_HEIGHT; y++) {
for (int x = 0; x < GBOARD_WIDTH; x++) {
if (mapInfo[mapNum][y][x] == -7) {//-7이 된 가시의 흔적을 찾아서 다시 가시를 보여줌
mapInfo[mapNum][y][x] = 7;
if (DetectCollision(curPosX, curPosY, blockModel[block_id]) == 7) {//제자리에 서있다가 가시피격당하는 경우
SetCurrentCursorPos(curPosX, curPosY);
DeleteBlock(blockModel[block_id]);
if (detX == 1 && detY == 2) {
curPosY -= 1;
}
else if (detX == 0 && detY == 1) {
curPosX += 2;
}
else if (detX == 2 && detY == 1) {
curPosX -= 2;
}
else if (detX == 1 && detY == 0) {
curPosY += 1;
}
SetCurrentCursorPos(curPosX, temp.Y);
ShowBlock(blockModel[block_id]);
collision = 1;
}
SetCurrentCursorPos(GBOARD_ORIGIN_X + x * 2, GBOARD_ORIGIN_Y + y);
if (mapInfo[mapNum][y - 1][x] == 0 && mapInfo[mapNum][y + 1][x] == 1) {
printf("△");
}
else if (mapInfo[mapNum][y - 1][x] == 1 && mapInfo[mapNum][y + 1][x] == 0) {
printf("▽");
}
else if (mapInfo[mapNum][y][x - 1] == 1 && mapInfo[mapNum][y][x + 1] == 0) {
printf("▷");
}
else if (mapInfo[mapNum][y][x - 1] == 0 && mapInfo[mapNum][y][x + 1] == 1) {
printf("◁");
}
}
}
}
if (collision == 1) {
SetCurrentCursorPos(curPosX, curPosY);
CollisionThorn();
}
clearflag = 0;// 다음 차례가 가시를 안보이게 할 차례라는 것을 알려줌
}
SetCurrentCursorPos(curPosX, curPosY);
}
void DrawMap() {
for (int y = 0; y < GBOARD_HEIGHT; y++) {
SetCurrentCursorPos(GBOARD_ORIGIN_X, GBOARD_ORIGIN_Y + y);
for (int x = 0; x < GBOARD_WIDTH; x++) {
switch (mapInfo[mapNum][y][x]) {
case 0: // 빈 공간
printf(" ");
break;
case -7: // 11.25 추가
printf(" ");
break;
case 1: // 고정 벽
SetConsoleOutputCP(437); // CP437: 확장 아스키 모드 사용
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15); // DrawMap - 꽉찬벽 사용 시 색 설정
printf("%c%c", 219, 219);
SetConsoleOutputCP(949); // 복구
break;
case 2: // 목적지
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
printf("★");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
break;
case 3: // 가시
if (x - 1 >= 0 && x + 1 <= GBOARD_WIDTH - 1) {
if ((mapInfo[mapNum][y][x - 1] == 0) && (mapInfo[mapNum][y][x + 1] == 1)) {
printf("◀");
break;
}
if ((mapInfo[mapNum][y][x + 1] == 0) && (mapInfo[mapNum][y][x - 1] == 1)) {
printf("▶");
break;
}
}
if (y - 1 >= 0 && y + 1 <= GBOARD_HEIGHT - 1) {
if ((mapInfo[mapNum][y - 1][x] == 0) && (mapInfo[mapNum][y + 1][x] == 1)) {
printf("▲");
break;
}
if ((mapInfo[mapNum][y - 1][x] == 1) && (mapInfo[mapNum][y + 1][x] == 0)) {
printf("▼");
break;
}
}
case 4: // 물약
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
printf("♥");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
break;
case 5: // 블랙홀
printf("@");
break;
case 6: // 운석
//printf("▣");
printf(" ");
break;
case 7: // 투명 가시
if (x - 1 >= 0 && x + 1 <= GBOARD_WIDTH - 1) {
if ((mapInfo[mapNum][y][x - 1] == 0) && (mapInfo[mapNum][y][x + 1] == 1)) {
printf("◁");
break;
}
if ((mapInfo[mapNum][y][x + 1] == 0) && (mapInfo[mapNum][y][x - 1] == 1)) {
printf("▷");
break;
}
}
if (y - 1 >= 0 && y + 1 <= GBOARD_HEIGHT - 1) {
if ((mapInfo[mapNum][y - 1][x] == 0) && (mapInfo[mapNum][y + 1][x] == 1)) {
printf("△");
break;
}
if ((mapInfo[mapNum][y - 1][x] == 1) && (mapInfo[mapNum][y + 1][x] == 0)) {
printf("▽");
break;
}
}
case 8: // 키
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
printf("ⓚ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
break;
}
}
}
}
void ShowBlock(char blockInfo[3][3])
{
int x, y;
COORD curPos = GetCurrentCursorPos();
for (y = 0; y < 3; y++)
{
for (x = 0; x < 3; x++)
{
SetCurrentCursorPos(curPos.X + (x * 2), curPos.Y + y);
if (blockInfo[y][x] == 97)
printf("◎");
if (blockInfo[y][x] == 98)
printf("△");
if (blockInfo[y][x] == 99)
printf("∥");
if (blockInfo[y][x] == -71)
printf("▷");
if (blockInfo[y][x] == -67)
printf("=");
if (blockInfo[y][x] == -28)
printf("▽");
if (blockInfo[y][x] == -73)
printf("◁");
}
}
SetCurrentCursorPos(curPos.X, curPos.Y);
}
int DetectCollision(int posX, int posY, char blockModel[3][3])
{
int x, y;
int arrX = (posX - GBOARD_ORIGIN_X) / 2;
int arrY = posY - GBOARD_ORIGIN_Y;
detX = 0;
detY = 0;
for (x = 0; x < 3; x++)
{
for (y = 0; y < 3; y++)
{
//물약 충돌 추가
if (mapInfo[mapNum][arrY + y][arrX + x] == 4 && blockModel[y][x] != 0) {
mapInfo[mapNum][arrY + y][arrX + x] = 0;// 물약 먹은걸 맵정보에 적용
CollisionPotion();
return 4;
}
//벽과 충돌
if (mapInfo[mapNum][arrY + y][arrX + x] == 1 && blockModel[y][x] != 0) {
detX = x;
detY = y;
return 0;
}
//가시와 충돌 수정
if (mapInfo[mapNum][arrY + y][arrX + x] == 3 && blockModel[y][x] != 0) {
detX = x;
detY = y;
return 3;
}
//투명 가시와 충돌 추가
if (mapInfo[mapNum][arrY + y][arrX + x] == 7 && blockModel[y][x] != 0) {
detX = x;
detY = y;
return 7;
}
//
//운석과 충돌
if (mapInfo[mapNum][arrY + y][arrX + x] == 6 && blockModel[y][x] != 0) {
CollisionMeteorite(arrY + y, arrX + x);
return 6;
}
//목적지와 충돌
if (mapInfo[mapNum][arrY + y][arrX + x] == 2 && blockModel[y][x] != 0) {
succ = 1;
return 2;
}
//운석과 충돌
if (mapInfo[mapNum][arrY + y][arrX + x] == 6 && blockModel[y][x] != 0) {
CollisionMeteorite(arrY + y, arrX + x);
return 6;
}
//블랙홀과 충돌
if (mapInfo[mapNum][arrY + y][arrX + x] == 5 && blockModel[y][x] != 0) {
return 5;
}
//키 충돌 추가 11.24
if (mapInfo[mapNum][arrY + y][arrX + x] == 8 && blockModel[y][x] != 0) {
mapInfo[mapNum][arrY + y][arrX + x] = 0;//키를 맵정보 에서 지움
CollisionKey();
return 8;
}
}
}
return 1;
}
void CollisionThorn() {
health--; //체력 -1
end = clock();
GameInfoUpdate();
if (IsGameOver()) return;
int deleteCnt = 0;
int showCnt = 0;
int moveCnt = 0;
while (1) {
if (periodflag == 1) {
ClearThorn();
periodflag = 0;
}
if (ProcessKeyInput())
break;
//11.27수정 Sleep(300)두번을 다음과 같이 바꿈
if (deleteCnt % 3 == 0)
DeleteBlock(blockModel[block_id]);
if (showCnt % 10 == 0)
ShowBlock(blockModel[block_id]);
if (moveCnt % 3 == 0 && mapNum >= 2)
moveObstacle();
moveCnt++;
deleteCnt++;
showCnt++;
end = clock();
GameInfoUpdate();
}
}
void CollisionPotion() {//포션함수
health++;
if (health > 3) {//최대체력
health = 3;
}
GameInfoUpdate();
}
//11.24 함수 추가
void CollisionKey() {
stageKey[mapNum]--;
if (stageKey[mapNum] <= 0) {//최소 0개
stageKey[mapNum] = 0;
}
}
void DeleteBlock(char blockInfo[3][3])
{
int x, y;
COORD curPos = GetCurrentCursorPos();
int arrX = (curPos.X - GBOARD_ORIGIN_X) / 2;
int arrY = curPos.Y - GBOARD_ORIGIN_Y;
for (y = 0; y < 3; y++)
{
for (x = 0; x < 3; x++)
{
SetCurrentCursorPos(curPos.X + 2 * x, curPos.Y + y);
if (mapInfo[mapNum][arrY + y][arrX + x] <= 7 && 1 <= mapInfo[mapNum][arrY + y][arrX + x])
continue;
if (blockInfo[y][x] == 97)
printf(" ");
if (blockInfo[y][x] == 98)
printf(" ");
if (blockInfo[y][x] == 99)
printf(" ");
if (blockInfo[y][x] == -71)
printf(" ");
if (blockInfo[y][x] == -67)
printf(" ");
if (blockInfo[y][x] == -28)
printf(" ");
if (blockInfo[y][x] == -73)
printf(" ");
}
}
SetCurrentCursorPos(curPos.X, curPos.Y);
}
void RedrawBlocks(char blockInfo[3][3])
{
int x, y;
COORD curPos = GetCurrentCursorPos();
int arrX = (curPos.X - GBOARD_ORIGIN_X) / 2;
int arrY = curPos.Y - GBOARD_ORIGIN_Y;
for (y = 0; y < 3; y++)
{
for (x = 0; x < 3; x++)
{
SetCurrentCursorPos(curPos.X + 2 * x, curPos.Y + y);
if (mapInfo[mapNum][arrY + y][arrX + x] <= 8 && 1 <= mapInfo[mapNum][arrY + y][arrX + x])
continue;
else
printf(" ");
}
}
SetCurrentCursorPos(curPos.X, curPos.Y);
ShowBlock(blockModel[block_id]);
}
int ShiftRight()
{
//운석과 충돌
if (DetectCollision(curPosX, curPosY, blockModel[block_id]) == 6) {
return 0;
}
//벽과 충돌
if (DetectCollision(curPosX + 2, curPosY, blockModel[block_id]) == 0)
return 0;
//가시와 충돌
if (DetectCollision(curPosX + 2, curPosY, blockModel[block_id]) == 3) {
CollisionThorn();
return 0;
}
//목적지와 충돌
if (DetectCollision(curPosX + 2, curPosY, blockModel[block_id]) == 2) {
CollisionDest();
return 0;
}
//블랙홀과 충돌
if (DetectCollision(curPosX + 2, curPosY, blockModel[block_id]) == 5) {
CollisionBlackhole();
return 0;
}
// 투명 가시와 충돌 추가
if (DetectCollision(curPosX + 2, curPosY, blockModel[block_id]) == 7)
{
CollisionThorn();
return 0;
}
DeleteBlock(blockModel[block_id]);
curPosX += 2;
SetCurrentCursorPos(curPosX, curPosY);
ShowBlock(blockModel[block_id]);
return 1;
}
int ShiftLeft()
{
//운석과 충돌
if (DetectCollision(curPosX, curPosY, blockModel[block_id]) == 6) {
return 0;
}
//벽과 충돌
if (DetectCollision(curPosX - 2, curPosY, blockModel[block_id]) == 0)
return 0;
//가시와 충돌
if (DetectCollision(curPosX - 2, curPosY, blockModel[block_id]) == 3) {
CollisionThorn();
return 0;
}
//목적지와 충돌
if (DetectCollision(curPosX - 2, curPosY, blockModel[block_id]) == 2) {
CollisionDest();
return 0;
}
// 투명 가시와 충돌 추가
if (DetectCollision(curPosX - 2, curPosY, blockModel[block_id]) == 7)
{
CollisionThorn();
return 0;
}
//블랙홀과 충돌
if (DetectCollision(curPosX - 2, curPosY, blockModel[block_id]) == 5) {
CollisionBlackhole();
return 0;
}
DeleteBlock(blockModel[block_id]);
curPosX -= 2;
SetCurrentCursorPos(curPosX, curPosY);
ShowBlock(blockModel[block_id]);
return 1;
}
int ShiftUp()
{
//운석과 충돌
if (DetectCollision(curPosX, curPosY, blockModel[block_id]) == 6) {
return 0;
}
//벽과 충돌
if (DetectCollision(curPosX, curPosY - 1, blockModel[block_id]) == 0)
return 0;
// 가시와 충돌
if (DetectCollision(curPosX, curPosY - 1, blockModel[block_id]) == 3)
{
CollisionThorn();
return 0;
}
//블랙홀과 충돌
if (DetectCollision(curPosX, curPosY - 1, blockModel[block_id]) == 5) {
CollisionBlackhole();
return 0;
}
// 투명 가시와 충돌
if (DetectCollision(curPosX, curPosY - 1, blockModel[block_id]) == 7)
{
CollisionThorn();
return 0;
}
//목적지와 충돌
if (DetectCollision(curPosX, curPosY - 1, blockModel[block_id]) == 2) {
CollisionDest();
return 0;
}
DeleteBlock(blockModel[block_id]);
curPosY -= 1;
SetCurrentCursorPos(curPosX, curPosY);
ShowBlock(blockModel[block_id]);
return 1;
}
int ShiftDown()
{
//운석과 충돌
if (DetectCollision(curPosX, curPosY, blockModel[block_id]) == 6) {
return 0;
}
//벽과 충돌
if (DetectCollision(curPosX, curPosY + 1, blockModel[block_id]) == 0)
return 0;
// 가시와 충돌
if (DetectCollision(curPosX, curPosY + 1, blockModel[block_id]) == 3)
{
CollisionThorn();
return 0;
}
// 투명 가시와 충돌
if (DetectCollision(curPosX, curPosY + 1, blockModel[block_id]) == 7)
{
CollisionThorn();
return 0;
}
//목적지와 충돌
if (DetectCollision(curPosX, curPosY + 1, blockModel[block_id]) == 2) {
CollisionDest();
return 0;
}
//블랙홀과 충돌
if (DetectCollision(curPosX, curPosY + 1, blockModel[block_id]) == 5) {
CollisionBlackhole();
return 0;
}
DeleteBlock(blockModel[block_id]);
curPosY += 1;
SetCurrentCursorPos(curPosX, curPosY);
ShowBlock(blockModel[block_id]);
return 1;
}
int IsGameOver()
{
//게임종료조건
//1. 생명이 0인 경우
//생명 0인 경우
if (health == 0) {
succ = -1;
return 1;
}
if (mapNum > 4) return 1;
return 0;
}
void RotateBlock() {
int colflag = 0;//충돌여부
int block_rotated = gravity;
if (DetectCollision(curPosX, curPosY, blockModel[block_rotated]) == 0) {
colflag = 1;
}
else if (DetectCollision(curPosX, curPosY, blockModel[block_rotated]) == 3) {//가시
colflag = 2;
}
else if (DetectCollision(curPosX, curPosY, blockModel[block_rotated]) == 7) {//투명가시
colflag = 2;
}
if (DetectCollision(curPosX, curPosY, blockModel[block_rotated]) == 2) {
//3스테이지용 임시기능
if (CollisionDest() == -1) {//회전시 목적지에 닿지만 키를 다 못먹은 경우
gravity--;//회전 불가판정
drawBar();
return;
}
}
if (DetectCollision(curPosX, curPosY, blockModel[block_rotated]) == 5) {//회전시 블랙홀에 닿는경우
CollisionBlackhole();
}
//추가끝//
DeleteBlock(blockModel[block_id]);
if (colflag == 1 || colflag == 2) {// 가시나 벽에 붙어서 이동하는 경우 충돌이 일어나기 때문에 좌표를 옮겨줌
int detobj;// 이중충돌 물체파악1203
if (detX == 1 && detY == 2) {
curPosY -= 1;
detobj = DetectCollision(curPosX, curPosY, blockModel[block_rotated]);
if (detobj != 1) {//양쪽이 물체인 경우 회전 불가하게 1203
curPosY -= 1;
gravity = gravitytemp;
if (detobj == 3 || detobj == 7 || colflag == 2) {
drawBar();
CollisionThorn();
}
}
}
else if (detX == 0 && detY == 1) {
curPosX += 2;
detobj = DetectCollision(curPosX, curPosY, blockModel[block_rotated]);
if (detobj != 1) {//양쪽이 물체인 경우 회전 불가하게 1203
curPosX -= 2;
gravity = gravitytemp;
if (detobj == 3 || detobj == 7 || colflag == 2) {
drawBar();
CollisionThorn();
}
}
}
else if (detX == 2 && detY == 1) {
curPosX -= 2;
detobj = DetectCollision(curPosX, curPosY, blockModel[block_rotated]);
if (detobj != 1) {//양쪽이 물체인 경우 회전 불가하게 1203
curPosX += 2;
gravity = gravitytemp;
if (detobj == 3 || detobj == 7 || colflag == 2) {
drawBar();
CollisionThorn();
}
}
}
else if (detX == 1 && detY == 0) {
curPosY += 1;
detobj = DetectCollision(curPosX, curPosY, blockModel[block_rotated]);
if (detobj != 1) {//양쪽이 물체인 경우 회전 불가하게 1203
curPosY -= 1;
gravity = gravitytemp;
if (detobj == 3 || detobj == 7 || colflag == 2) {