/*项目名称:黑客帝国流星雨代码
/作者:AJIN
*/
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<time.h>
void initrain();
void downrain();
void drowrain();
struct COOR //坐标
{
int x;
int y;
}coor;
struct RAIN //雨水结构体
{
int n;
struct COOR scr[15][10];
}rain;
int main() //主函数入口-------------------------------
{
initrain();
while (1)
{
downrain();
drowrain();
Sleep(100);
cleardevice();
}
return 0;
}
void initrain() //初始化界面
{
initgraph(640, 480);
setbkcolor(BLACK);
cleardevice();
srand((unsigned)time(NULL));
rain.n = 15;
for (int i = 0; i < 15; i++) //初始化15个首雨滴
{
rain.scr[i][0].x = ((rand() % 60)+2) * 10;
rain.scr[i][0].y = ((rand() % 44)+2) * 10;
for (int j = 0; j < 10; j++)
{
if (rain.scr[i][0].x == rain.scr[j][0].x|| rain.scr[i][0].y == rain.scr[j][0].y)
{
rain.scr[i][0].x = ((rand() % 60) + 2) * 10;
rain.scr[i][0].y = ((rand() % 44) + 2) * 10;
}
}
}
}
void drowrain()//化雨
{
for (int j = 0; j < 15; j++)
{
for (int i = 0; i < rain.n; i++)
{
setfillcolor(RGB(rand() % 250, rand() % 250, rand() % 250));
fillrectangle(rain.scr[j][i].x, rain.scr[j][i].y, rain.scr[j][i].x + 10, rain.scr[j][i].y + 10);
}
}
}
void downrain()//下雨
{
for (int j = 0; j <15; j++)
{
for (int i = rain.n - 1; i >=0; i--)
{
rain.scr[j][i+1].x = rain.scr[j][i].x;
rain.scr[j][i+1].y = rain.scr[j][i].y;
}
}
for (int j = 0; j < 15; j++)
{
rain.scr[j][0].y += 10;
}
}