本文实例为大家分享了C语言实现漂亮的烟花效果展示的具体代码,供大家参考,具体内容如下
程序名称:祝福烟花,祝福朋友
编译环境:VC++6.0 && easyx(立冬版)
#include
#include
#include
#include
#include
#include
#include // 使用该计时器必须包含的文件
#pragma comment ( lib, "Winmm.lib" )
/***** 宏定义区 ******/
#define NUM 13 // 烟花种类数量宏定义
/***** 结构定义区 **********/
// 烟花结构
struct FIRE
{
int r; // 当前爆炸半径
int max_r; // 爆炸中心距离边缘最大半径
int x, y; // 爆炸中心在窗口的坐标
int cen_x, cen_y; // 爆炸中心相对图片左上角的坐标
int width, height; // 图片的宽高
int xy[240][240]; // 储存图片像素点
bool show; // 是否绽放
bool draw; // 开始输出像素点
DWORD t1, t2, dt; // 绽放速度
}Fire[NUM];
// 烟花弹结构
struct JET
{
int x, y; // 喷射点坐标
int hx, hy; // 最高点坐标------将赋值给 FIRE 里面的 x, y
int height; // 烟花高度
bool shoot; // 是否可以发射
DWORD t1, t2, dt; // 发射速度
IMAGE img[2]; // 储存花弹一亮一暗图片
byte n : 1; // 图片下标
}Jet[NUM];
// happy birthday 艺术字结构
struct HAPPY // 储存 Happy Birthday 艺术字图片
{
int x, y; // 每个字的图片的左上角坐标
IMAGE img; // 储存单个字图片
static int num; // 字母序号
}Happy[NUM];
int HAPPY::num = 0;
// For.2012の夭女 结构
struct WISH // 滚动祝福图片结构
{
int x, y; // 图片左上角坐标
DWORD t1, t2, dt; // 图片运动时间间隔
IMAGE img; // 储存图片
int dxy; // 每次的移动量
byte dir : 1; // 限制两个滚动方向
}Wish;
/**** 函数申明区 ****/
void Init ( int ); // 初始化烟花
void Load ( ); // 加载烟花图片
void Shoot ( ); // 发射烟花
void Chose ( DWORD& ); // 筛选烟花
void Wishing( ); // 滚动祝福
void Style ( DWORD& ); // 发射样式
void Show ( DWORD* ); // 绽放烟花
// 主函数
void main()
{
initgraph( 1200, 800 );
srand( time(0) );
// 播放背景音乐
mciSendString( "open ./fire/bk.mp3 alias bk", 0, 0, 0 );
mciSendString( "play bk repeat", 0, 0, 0 );
setfillstyle( 0 );
setfont ( 36, 0, "楷体" );
setcolor ( YELLOW );
outtextxy ( 370, 100, "yy滺滺__出厂 .... ^_^" );
DWORD t1 = timeGetTime(); // 筛选烟花计时
DWORD st1 = timeGetTime(); // 播放花样计时
DWORD* pMem = GetImageBuffer(); // 获取窗口显存指针
for ( int i = 0; i < NUM; i++ ) // 初始化烟花
{
Init( i );
}
Load(); // 将烟花图片信息加载进相应结构中
BeginBatchDraw(); // 开始批量绘图
while ( !kbhit