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.0511 sec