谁说程序员不懂浪漫?
for(birth; death; ){ love++; }
do{ love++; } while (death)
可执行的exe文件我放在文章后面了!
直接双击点开就可以使用了
最终效果:
![](https://img-blog.csdnimg.cn/96c160ca54804379be39feaeff1394bf.bmp)
![](https://img-blog.csdnimg.cn/63cbec7f14f14f0fa4ff59736cd5f8ca.bmp)
![](https://img-blog.csdnimg.cn/a3625c989f4a43b8af12c15651db7ad7.bmp)
![](https://img-blog.csdnimg.cn/6055a1afb283449889f481441368d7cc.bmp)
运行环境:VS2019 、 easyx图形库
1.头文件:
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <mmsystem.h>
#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, y
int 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~50
settextstyle((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..4
getimage(&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 < 13; i++) {
bullets[i].t2 = timeGetTime();
if (bullets[i].t2 - bullets[i].t1 > 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文件,可@博主本人或私聊!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)