테트리스 그림자를 어떻게 넣는지 모르겟습니다
츄릅
질문 제목 : 테트리스 그림자를 넣는방법좀 알려주세요테트리스 그림자 넣기질문 내용 :어떤분이 정리하신것을 봣지만 이해를 못하겟어서 꿈돌이에서 테트리스 소스를 퍼왓는대요 그림자를 어떻게 만들어야하는지 몰르겟습니다.
#include stdio.h
#include stdlib.h
#include string.h
#include ctype.h
#include time.h
#include math.h#include windows.h
#include conio.h#define esc 27
#define enter 13
#define space 32
#define left 75
#define right 77
#define up 72
#define down 80
#define winx 2
#define winy 2
#define winwidth 12
#define winheight 20
#define free_drop 0
#define move_down 1
#define move_left 2
#define move_right 3
#define move_drop 4
#define rotation 5void gotoxy(int x, int y);
void checkkey();
void display();
void update();
void start();
int iscollision();
void fixbrick();
void newbrick();
void barcheck();int brick_x, brick_y;
int brick_shape, brick_rotation;
int win[winheight][winwidth];
int brick_action;
int free_drop_delay = 20;
int free_drop_count;
int brick[7][4][4][4] = {
0, 1, 0, 0,
1, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 0,
0, 1, 1, 0,
0, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 1, 1, 0,
0, 1, 0, 0,
0, 0, 0, 0,
0, 1, 0, 0,
1, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0,
0, 1, 1, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 0,
0, 1, 1, 0,
0, 0, 1, 0,
0, 0, 0, 0,
0, 1, 1, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 0,
0, 1, 1, 0,
0, 0, 1, 0,
0, 0, 0, 0,
1, 1, 0, 0,
0, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 0,
1, 1, 0, 0,
1, 0, 0, 0,
0, 0, 0, 0,
1, 1, 0, 0,
0, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 0,
1, 1, 0, 0,
1, 0, 0, 0,
0, 0, 0, 0,
1, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0,
0, 0, 1, 0,
1, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 1, 1, 0,
1, 0, 0, 0,
0, 0, 0, 0,
0, 1, 1, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 1, 1, 0,
0, 0, 1, 0,
0, 0, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
1, 0, 0, 0,
1, 1, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0,
1, 1, 1, 1,
0, 0, 0, 0,
0, 0, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0,
1, 1, 1, 1,
0, 0, 0, 0,
0, 0, 0, 0,
1, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
int gameover = 0;
int gamepoint = 0;void main()
{
start();
while (!gameover)
{
display();
checkkey();
update();
sleep(40);
}
}void gotoxy(int x, int y)
{
{
coord pos = { x, y };
setconsolecursorposition(getstdhandle(std_output_handle), pos);
}void start()
{
int x, y;
newbrick();
free_drop_count = free_drop_delay;
for (x = 0; xwinwidth; x++)
{
for (y = 0; ywinheight; y++)
{
if (x == 0 || x == winwidth - 1 ||
y == 0 || y == winheight - 1)
{
win[y][x] = 2;
}
else
{
win[y][x] = 0;
}
}
}
}int iscollision()
{
int x, y;
for (y = 0; y4; y++)
{
for (x = 0; x4; x++)
{
if (brick[brick_shape][brick_rotation][y][x] == 1)
{
if (win[brick_y + y][brick_x + x] != 0)
{
return 1;
}
}
}
}
return 0;
}void fixbrick()
{
int x, y;
for (y = 0; y4; y++)
{
for (x = 0; x4; x++)
{
if (brick[brick_shape][brick_rotation][y][x] == 1)
{
win[brick_y + y][brick_x + x] = 1;
}
}
}
}void newbrick()
{
srand(time(null));
brick_x = winwidth / 2;
brick_y = 1;
brick_shape = rand() % 7;
brick_rotation = 0;
brick_action = free_drop;
}void barcheck()
{
int x, y, bar, i, j;
for (y = 1; ywinheight - 1; y++)
{
bar = 0;
for (x = 1; xwinwidth - 1; x++)
{
bar += win[y][x];
}
if (bar == winwidth - 2)
{
gamepoint++;
if (gamepoint % 20 == 0) free_drop_delay--;
if (free_drop_delay 0) free_drop_delay = 0;
for (i = y - 1; i0; i--)
{
for (j = 1; jwinwidth - 1; j++)
{
win[i + 1][j] = win[i][j];
}
}
}
}
}void display()
{
int x, y;
for (y = 0; ywinheight; y++)
{
gotoxy(winx, winy + y);
for (x = 0; xwinwidth; x++)
{
if (win[y][x] == 1) printf(■);
else if (win[y][x] == 2) printf(□);
else printf( );
}
printf(\n);
}
for (y = 0; y4; y++)
{
for (x = 0; x4; x++)
{
if (brick[brick_shape][brick_rotation][y][x] == 1)
{
gotoxy(winx + (brick_x + x) * 2, winy + brick_y + y);
printf(■);
}
}
}
gotoxy(30, 25);
printf(point = %d, gamepoint);
}void update()
{
switch (brick_action)
{
case move_drop:
do{
brick_y++;
} while (!iscollision());
brick_y--;
if (brick_y == 1) gameover = 1;
fixbrick();
barcheck();
newbrick();
free_drop_count = free_drop_delay;
brick_action = free_drop;
break;
case move_left:
brick_x--;
if (iscollision()) brick_x++;
brick_action = free_drop;
break;
case move_right:
brick_x++;
if (iscollision()) brick_x--;
brick_action = free_drop;
break;
case move_down:
brick_y++;
if (iscollision())
{
brick_y--;
if (brick_y == 1) gameover = 1;
fixbrick();
barcheck();
newbrick();
free_drop_count = free_drop_delay;
}
brick_action = free_drop;
break;
case free_drop:
free_drop_count--;
if (free_drop_count 0)
{
free_drop_count = free_drop_delay;
brick_action = move_down;
}
break;
case rotation:
brick_rotation++;
if (brick_rotation 3) brick_rotation = 0;
if (iscollision())
{
brick_rotation--;
if (brick_rotation 0) brick_rotation = 3;
}
brick_action = free_drop;
break;
default:
break;
}
}void checkkey()
{
int key;
if (_kbhit() != 0)
{
key = _getch();
if (key == 224)
{
key = _getch();
}
switch (key)
{
case esc:
gameover = 1;
break;
case enter:
break;
case space:
brick_action = move_drop;
break;
case left:
brick_action = move_left;
break;
case right:
brick_action = move_right;
break;
case up:
brick_action = rotation;
break;
case down:
brick_action = move_down;
break;
default:
brick_action = free_drop;
break;
}
}
}
-
푸른잎
뭘보고 공부하면 저정도라도 타이핑가능할가요?ㅜ
-
횃대비
저가 퍼온거라서 그냥 보고 소스 공부할려고 하는거라서요. 써주시면 안될까요??
-
세움
4차원배열 ㄷㄷ하군요