U E D R , A S I H C RSS

데블스캠프2005/게임만들기/제작과정예제

2005/게기/



.
start(), color .
, 1~10까 .
block .
~cpp 
block[0][0]=1;
. 결과 .

test01.jpg

~cpp 
block[x][y]= ;
, 0 고 그 .
block_next, next 34 .
.
~cpp 
block_next[x][y]= ;


.
고, .


~cpp 
1.  .
2.    next .
3.next     .
4. .
5. .
6.  ,  .
7.  .

.
, 기게 .



.
n 고, n ,
T(0,3)(1,1)(1,1) . , .
0 .

) . , .
~cpp 
	{{
	{0,0,0,0},
	{2,2,2,2},
	{0,0,0,0},
	{0,0,0,0}}
	,{
	{0,0,2,0},
	{0,0,2,0},
	{0,0,2,0},
	{0,0,2,0}}
	,{
	{0,0,0,0},
	{2,2,2,2},
	{0,0,0,0},
	{0,0,0,0}}
	,{
	{0,0,2,0},
	{0,0,2,0},
	{0,0,2,0},
	{0,0,2,0}}
},

next


start() srand((int)time(NULL));, ,
. 그고 그 rand() ,
next .
고, 거기 .

key_Right() 고, .

test02.jpg

)
~cpp 
	int block_id;
	block_id=rand()%7;
	for (register int i=0;i<3;++i)
		for (register int j=0; j<4; ++j)
			block_next[i][j]=block_type[block_id][0][i][j];
	prv_block=block_id; // .




. .
간, 그 , 게 .
, x,y값 .
고, .
next .

key_Left() 고, , .

)
~cpp 
	for (register int i=0;i<3; ++i)
	{
		for (register int j=0; j<4; ++j)
		{
			if (0!=block_type[prv_block][0][i][j])
			{
				if (0==block[3+i][16+j])
					block[3+i][16+j]=block_type[prv_block][0][i][j];
				else
					game_end();
			}
		}
	}
	x=3;  // x
	y=16; // y
	shape=0; //   
	now_block=prv_block; //   ID

test03.jpg



. , 꾸고, . , . , . , .

, , 고, now_time() .

test04.jpg


) . -1 0 , 1 .
.


~cpp 
int move_block(int where)// -1 0  1
{
	int temp_x=x+where;
	int temp_y=y-(where+1)%2;
	int temp_block[4][4]={0,};
	int ground[4]={0,};
	int side[2][4]={0,};
	int swit[2][4]={0,};
         
         //   .         

	for (register int i=0;i<4; ++i)
	{
		for (register int j=0; j<4; ++j)
		{
			if (0!=block_type[now_block][shape][i][j])
			{
				if (i>=side[0][j] && 0==swit[1][j])
				{
					side[0][j]=i;
					swit[1][j]=1;
				}
				side[1][j]=i;
				if (j>=ground[i] && 0==swit[0][i])
				{
					ground[i]=j;
					swit[0][i]=1;
				}
			}
		}
	}

         //     .   1 .

	for (i=0;i<4; ++i)
	{
		for (register int j=0; j<4; ++j)
		{
			if (0!=block_type[now_block][shape][i][j])
			{
				if (temp_x+i<0 || temp_x+i>9 )
					return 1;
				else if (temp_y+j<0 || temp_y+j>19 )
					return 1;
				else if (0!=block[temp_x+i][temp_y+j])
				{
					if (ground[i]+1>j && where==0)
						return 1;
					else if (side[0][j]+1>i && where==-1)
						return 1;
					else if (side[1][j]-1<i && where==1)
						return 1;
				}
			}
		}
	}

         //    .

	for (i=0;i<4; ++i)
		for (register int j=0; j<4; ++j)
			if (0!=block_type[now_block][shape][i][j])
				block[x+i][y+j]=0;

         //  .

	for (i=0;i<4; ++i)
		for (register int j=0; j<4; ++j)
			if (0!=block_type[now_block][shape][i][j])
				block[temp_x+i][temp_y+j]=block_type[now_block][shape][i][j];
	x=temp_x;y=temp_y;
	return 0;
}



, , 공간 고, 공간 . , , .

)

~cpp 
	int temp_x=x;
	int temp_y=y;
	int temp_shape=(shape+1)%4;
	int crash=2;
	int temp_block[4][4]={0,};

         //  ,  공간  .

	while (2==crash)
	{
		for (register int i=0;i<4; ++i)
			for (register int j=0; j<4; ++j)
				temp_block[i][j]=0;
		crash=0;
		for (i=0;i<4; ++i)
			for (register int j=0; j<4; ++j)
				if (0!=block_type[now_block][shape][i][j]&& 0<=i+x-temp_x && 3>=i+x-temp_x )
					temp_block[i+x-temp_x][j]=1;
		for (i=0;i<4; ++i)
		{
			for (register int j=0; j<4; ++j)
			{
				if (0!=block_type[now_block][temp_shape][i][j])
				{
					if (temp_x+i<0)
					{
						temp_x+=1;crash=2;
					}
					else if (temp_x+i>9 )
					{
						temp_x-=1;crash=2;
					}
					else if (0!=block[temp_x+i][temp_y+j] && 1!=temp_block[i][j])
						crash=1;
				}
			}
		}
	}

         //  공간 ,   .

	if (1==crash)
		return 0;
	for (register int i=0;i<4; ++i)
		for (register int j=0; j<4; ++j)
			if (0!=block_type[now_block][shape][i][j])
				block[x+i][y+j]=0;

         // .

	for (i=0;i<4; ++i)
		for (register int j=0; j<4; ++j)
			if (0!=block_type[now_block][temp_shape][i][j])
				block[temp_x+i][temp_y+j]=block_type[now_block][temp_shape][i][j];

         // .

	x=temp_x;y=temp_y;shape=temp_shape;
	return 0;



, . , .
for , , .

)
~cpp 
void delete_block()
{
	for (register int line=y; line<y+4; ++line)
		for (register int i=0; i<10; ++i)
			if (0==block[i][line])
				i=10;   //  , 그  .
			else
				if (9==i) //    .
				{
					for (register int k=0; k<10; ++k)
						block[k][line]=0;
					for (k=line; k<19; ++k) //  .
						for (register int l=0; l<10; ++l)
							block[l][k]=block[l][k+1];
					for (k=0; k<10; ++k)
						block[k][19]=0;
					--line;
				}
}



, 고, 그 경 .
고 그 결과 꾸고, time_delay .

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:59
Processing time 0.0233 sec