> 文档中心 > 情人节浪漫表白,程序员的专属浪漫-----烟花表白

情人节浪漫表白,程序员的专属浪漫-----烟花表白

谁说程序员不懂浪漫?

for(birth; death; ){ love++; }

do{ love++; } while (death)

可执行的exe文件我放在文章后面了!

直接双击点开就可以使用了

最终效果:

 

 

 

运行环境:VS2019 、 easyx图形库

1.头文件:

#include #include #include #include #include #include #pragma comment ( lib, "Winmm.lib" )#define PI 3.14#define NUM 13

2.定义烟花弹、烟花结构体

 struct Fire{ ...... }fires[NUM];

struct Fire{int r;// 当前爆炸半径int max_r;// 爆炸中心距离边缘最大半径int x, y;// 爆炸中心在窗口的坐标int cent2LeftTopX, cent2LeftTopY;// 爆炸中心相对图片左上角的坐标int width, height;// 图片的宽高int pix[240][240];// 储存图片像素点bool show;// 是否绽放bool draw;// 开始输出像素点DWORD t1, t2, dt;// 绽放速度}fires[NUM];

struct Bullet{. ....... }bullets[NUM];

// 烟花弹结构struct Bullet{int x, y;// 烟花弹的当前坐标int topX, topY;// 最高点坐标------将赋值给 FIRE 里面的 x, yint height;// 烟花高度bool shoot;// 是否可以发射DWORD t1, t2, dt;// 发射速度IMAGE img[2];// 储存花弹一亮一暗图片unsigned char n : 1;// 图片下标 n++}bullets[NUM];

3.定义一些函数

开场的表白函数:

//表白字幕部分void welcome() {setcolor(YELLOW);  //修改画笔的颜色为黄色// 模拟字幕运动规矩int R = 180;int offX = 600; //圆心偏移量int offY = 200; //圆心偏移量for (int a = 90; a >= -210; a -= 6) {int x = offX + R * cos(a / 180.0 * PI);int y = offY + R * sin(a / 180.0 * PI);// 在指定的 (x,y)画一个圆,半径10//circle(x, y, 10);cleardevice(); //清除屏幕// a:  90 ~ -210// 90-a:  0~300// (90-a)/300.0: 0~1// (90-a)/300.0 * 50 = 0~50settextstyle((90 - a) / 300.0 * 50, 0, "楷体");// outtextxy在指定的位置,输入文字outtextxy(x - 80, y, "520——浪漫表白日");outtextxy(x - 10, y + 100, "献给我挚爱的女神");Sleep(18);}getchar();  //获取一个字符,实现暂停效果cleardevice();settextstyle(40, 0, "楷体");outtextxy(400, 200, "我爱你");outtextxy(400, 250, "往后余生是你");outtextxy(400, 300, "风雪是你");outtextxy(400, 350, "平淡是你");outtextxy(400, 400, "清贫是你");outtextxy(400, 450, "荣华是你");outtextxy(400, 500, "目光所致也是你");getchar();}

 加载图片的函数:

// 加载图片void loadFireImages(){/**** 储存烟花的像素点颜色 ****/IMAGE fm, gm;loadimage(&fm, "fire/flower.jpg");for (int i = 0; i < 13; i++){SetWorkingImage(&fm);getimage(&gm, i * 240, 0, 240, 240);SetWorkingImage(&gm);for (int a = 0; a < 240; a++)for (int b = 0; b < 240; b++)fires[i].pix[a][b] = getpixel(a, b);}/**** 加载烟花弹 ************/IMAGE sm;loadimage(&sm, "fire/shoot.jpg");for (int i = 0; i < 13; i++){SetWorkingImage(&sm);int n = rand() % 5; //0..4getimage(&bullets[i].img[0], n * 20, 0, 20, 50);// 暗getimage(&bullets[i].img[1], (n + 5) * 20, 0, 20, 50);// 亮}//设置绘图设备为默认绘图窗口,就是当前游戏窗口SetWorkingImage();// 设置回绘图窗口}

烟花弹的升空函数

// 烟花弹升空void shoot() {for (int i = 0; i  bullets[i].dt && bullets[i].shoot == true) {// 擦除putimage(bullets[i].x, bullets[i].y, &bullets[i].img[bullets[i].n], SRCINVERT);// 更新烟花弹的位置和图片状态if (bullets[i].y > bullets[i].topY) {bullets[i].n++;bullets[i].y -= 5;}// 在新位置上,重新绘制putimage(bullets[i].x, bullets[i].y, &bullets[i].img[bullets[i].n], SRCINVERT);/**** 上升到高度的 3 / 4,减速 *****/// 即距离最高点还有1/4的时候,减速if ((bullets[i].y - bullets[i].topY) * 4 < bullets[i].height)bullets[i].dt = rand() % 4 + 10; // 10..13/**** 上升到最大高度 *****/if (bullets[i].y <= bullets[i].topY) {// 擦除烟花弹putimage(bullets[i].x, bullets[i].y, &bullets[i].img[bullets[i].n], SRCINVERT);// 准备渲染“烟花”fires[i].x = bullets[i].topX + 10;// 在烟花弹中间爆炸fires[i].y = bullets[i].topY;// 在最高点绽放fires[i].show = true;// 开始绽放bullets[i].shoot = false;// 停止发射 // 关闭点烟花的音效,并播放爆炸的音效, 并重新打开点烟花的音效char c1[64], c2[64];sprintf(c1, "close s%d", i);sprintf(c2, "play f%d", i);mciSendString(c1, 0, 0, 0);mciSendString(c2, 0, 0, 0);sprintf_s(c1, sizeof(c1), "open fire/shoot.mp3 alias s%d", i);mciSendString(c1, 0, 0, 0);}// 更新烟花弹的时间bullets[i].t1 = bullets[i].t2;}}}

注意:以上只是部分代码,稍后我会把源码上传~

文章中无法发exe文件,可@博主本人或私聊!