怎么用c写 下雨或下雪的 程序
发布网友
发布时间:2022-05-11 16:02
我来回答
共3个回答
热心网友
时间:2023-10-14 18:01
初始化
void Init_Data()
{
int i;
for( i=0; i< POINT; i++)
{
Snow[i].x=0;
Snow[i].y=0;
Snow[i].size=0;
}
for( i=0; i<MaxX; i++)
Map[i]=MaxY;
}
显示:
void MakeSnow()
{
int i;
if( CurSnow>=POINT ) return;
for( i=0; Snow[i].size; i++ )
;
CurSnow++;
Snow[i].x=random(MaxX);
Snow[i].y=random(DOWNSPEED);
Snow[i].size=random(MaxSize)+1;
}
设定显示坐标
void ShowSnow( int x, int y, int size, int flag )
{
int color=0;
if ( flag ) color=15;
switch( size )
{
case 1:
putpixel( x, y, color );
break;
case 2:
setcolor( color );
line( x-1, y-1, x+1, y+1 );
line( x-1, y+1, x+1, y-1 );
break;
case 3:
setcolor( color );
line( x-1, y-1, x+1, y+1 );
line( x-1, y+1, x+1, y-1 );
/*
line( x-2, y-2, x+2, y+2 );
line( x-2, y+2, x+2, y-2 );*/
line( x-2, y, x+2, y );
line( x, y-2, x, y+2 );
break;
}
}
雪花移动效果:
void Move( int n, int tox, int toy )
{
int x, y, size, i, j;
float person;
x=Snow[n].x;
y=Snow[n].y;
size=Snow[n].size;
/* check end */
j=y;
if( x<tox )
{
person=(DOWNSPEED *1.0) / ( tox-x )*1.0;
for( i=x; i<=tox; i++ )
{
if( j>=Map[i] )
{
tox=i-size;
break;
}
j+=(int)( (i-x+1)*person );
}
}
else if( x>tox )
{
person=(DOWNSPEED *1.0) / ( x-tox )*1.0;
for( i=x; i>=tox; i-- )
{
if( j>=Map[i] )
{
tox=i+size;
break;
}
j+=(int)( (x-i+1)*person );
}
}
if( y+DOWNSPEED>=Map[tox] )
{
switch( size )
{
case 1:
Map[x]--;
break;
case 2:
Map[x]-=2;
if( x>0 && Map[x-1]>Map[x] ) Map[x-1]=Map[x];
if( x<MaxX-1 && Map[x+1]>Map[x] ) Map[x+1]=Map[x];
break;
case 3:
Map[x]-=3;
if( x>1 && Map[x-2]>Map[x] ) Map[x-1]=Map[x];
if( x>0 && Map[x-1]>Map[x] ) Map[x-1]=Map[x];
if( x<MaxX-2 && Map[x+2]>Map[x] ) Map[x+1]=Map[x];
if( x<MaxX-1 && Map[x+1]>Map[x] ) Map[x+1]=Map[x];
break;
}
CurSnow--;
y=Map[x]+size;
Snow[n].x=x;
Snow[n].y=y;
Snow[n].size=0;
}
else /* not end */
{
Snow[n].x=tox;
Snow[n].y=toy;
}
}
热心网友
时间:2023-10-14 18:01
http://download.csdn.net/down/769589/chensi3375看看这个是不是
热心网友
时间:2023-10-14 18:02
刚开始学C,建议不好碰这东西,保证你看不懂