03
代码分享
int x, y;
int step;
int color;
}star[MAXSTAR];
//流星的属性
struct Meteor
{undefined
int x, y;
张伦硕真的爱钟丽缇吗int step;
int style;
}meteor[MAXMETEOR];
//初始化星星
void initStar(int i)
{undefined
star[i].x = rand() % 1000; //[0,999]
star[i].y = rand() % 600;披头士成员
唐禹哲资料
star[i].step = rand() % 6+3; //[0,5]
star[i].color = RGB(rand() % 255, rand() % 255, rand() % 255); }
//画星星和移动星星
void moveStar(int i)
{undefined
//画像素点
putpixel(star[i].x, star[i].y, star[i].color);
//移动处理
star[i].x += star[i].step;
//如果移动到了窗⼝外⾯
if (star[i].x > 1000)
{undefined
putpixel(star[i].x, star[i].y, star[i].color);
initStar(i);
}
}
void initMeteor(int i)
{undefined
meteor[i].x = rand() % 2000-1000;//[-1000,999] meteor[i].y = -600;//[0,599]-600-->[-600,-1]
meteor[i].step = rand() % 30 + 2;
meteor[i].style = rand() % 3; //[0,2]-->0,1,2
}
//初始化数据
void initDate(int i)
{undefined
//加载图⽚
loadimage(&img1, "1.jpg", 30, 30);
loadimage(&img2, "2.jpg",40, 40);
loadimage(&img3, "3.jpg", 50, 50);
for (i = 0; i < MAXSTAR; i++)
{undefined
initStar(i);
}
for (i = 0; i < MAXMETEOR; i++)
{undefined
initMeteor(i);
}
}
//画流星:贴图
void drawMeteor(int i)
{undefined
for (i = 0; i < MAXMETEOR; i++)火影忍者禁图h>不接电话的你 歌词
{undefined
switch (meteor[i].style)
{undefined
case 0:
putimage(meteor[i].x, meteor[i].y, &img1,SRCPAINT); break;
putimage(meteor[i].x, meteor[i].y, &img2, SRCPAINT);
break;
case 2:
putimage(meteor[i].x, meteor[i].y, &img3, SRCPAINT);
break;
}
}
}
//移动流星
void moveMeteor(int i)
{undefined
for (i = 0; i < MAXMETEOR; i++)
{undefined
meteor[i].x += meteor[i].step;
meteor[i].y += meteor[i].step;
//如果流星跑到窗⼝外⾯
if (meteor[i].x>1000 || meteor[i].y > 600)
{undefined
initMeteor(i);
}
}
}
//⽂字输出
void text()
{undefined
settextcolor(RGB(rand() % 255, rand() % 255, rand() % 255));
settextstyle(30, 0, "楷体");
char* text[50] = { "X", "X", "X", "我", "喜", "欢", "你", "做", "我", "⼥", "朋", "友", "吧", "!", }; int x = 450, y = 100;
for (int i = 0; i < 14; i++)
{undefined
if (i<7)
outtextxy(x, y + i * 50, text[i]);
outtextxy(x+100, y + (i-7) * 50, text[i]);
}
}
int main()
{undefined
initgraph(1000, 600);
mciSendString("open 2.mp3", 0, 0, 0); mciSendString("play 2.mp3 repeat", 0, 0, 0); srand((unsigned int)time(NULL));//随机函数种⼦setbkmode(TRANSPARENT);
int i = 0;
initDate(i);
while (1)
{undefined
cleardevice();
for (i = 0; i < MAXSTAR; i++)
{undefined
moveStar(i);
}张雨绮整容前
drawMeteor(i);
moveMeteor(i);
text();
Sleep(100);
}
_getch();
closegraph();
//system("pause");
return 0;
}