前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >流星雨

流星雨

作者头像
对弈
发布2019-09-04 15:50:52
4870
发布2019-09-04 15:50:52
举报
文章被收录于专栏:用户3029758的专栏
代码语言:javascript
复制
#include <graphics.h>
#include <time.h>
#include <mmsystem.h>
#pragma comment(lib,"winmm.lib")


#define MAXSTAR 100   //流星最大数量
#define MAXSTAR1 1000  //星星最大数量


IMAGE img1, img2;




//星星
struct STAR1
{
int x, y;  //星星坐标
int step;  //星星移动的速度
int color;  //星星的颜色
}star1[MAXSTAR1];


//流星
struct STAR
{
int x, y;
int step;
int style; //图片样式
}star[MAXSTAR];




void initData();
void initStar1(int i);
void initStar(int i);
void moveStar1(int i);
void moveStar();
void drawStar();




int main()
{
initData();
mciSendString("open 凉凉.mp3 alias music", 0, 0, 0);
mciSendString("play music repeat", 0, 0, 0);


while (1)
{
BeginBatchDraw();  //开始绘图界面
cleardevice();
for (int i = 0; i < MAXSTAR1; i++)
{
moveStar1(i);
}
moveStar();
drawStar();
Sleep(50);
EndBatchDraw();   //结束绘图界面,绘制上面所有的操作
}


closegraph();
return 0;


}




void initData()
{
srand((unsigned int)time(NULL));
initgraph(640, 480);
//初始化数据
loadimage(&img1, "2.jpg", 50, 50);
loadimage(&img2, "3.jpg", 50, 50);
//初始化星星
int i = 0;
for (i = 0; i < MAXSTAR1; i++)
{
initStar1(i);
star1[i].x = rand() % 640;
}
//初始化流星
for (i = 0; i < MAXSTAR; i++)
{
initStar(i);
}
}




void initStar1(int i)
{
star1[i].x = 0;
star1[i].y = rand() % 480;
star1[i].step = rand() % 5;
star1[i].color = RGB(star1[i].step * 51, star1[i].step * 51, star1[i].step * 51);
}


void initStar(int i)
{
star[i].x = rand() % 1280 - 640;  //-640-639
star[i].y = -144;
do
{
star[i].step = rand() % 30 + 1;
} while (star[i].step < 5);
star[i].style = rand() % 3 + 1;
}


//绘制移动星星
void moveStar1(int i)
{
putpixel(star1[i].x, star1[i].y, 0);
star1[i].x += star1[i].step;
if (star1[i].x>640)
initStar1(i);
putpixel(star1[i].x, star1[i].y, star1[i].color);
}


void moveStar()
{
for (int i = 0; i < MAXSTAR; i++)
{
star[i].x += star[i].step;
star[i].y += star[i].step*0.8;
}
}




void drawStar()
{
for (int i = 0; i < MAXSTAR; i++)
{
switch (star[i].style)
{
case 1:
putimage(star[i].x, star[i].y, &img1, SRCPAINT);
break;
case 2:
putimage(star[i].x, star[i].y, &img2, SRCPAINT);
break;
}
}
}






*/

声明:本文为原创,作者为 对弈,转载时请保留本声明及附带文章链接:http://www.duiyi.xyz/c%e5%ae%9e%e7%8e%b0%e9%9b%b7%e9%9c%86%e6%88%98%e6%9c%ba-57/

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-08-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档