这是一个利用C语言编写放烟花的程序(同时也可以播放音乐),供大家参考,具体内容如下
代码如下
#pragma once
#include
#include //图形界面库头文件
#include //计算圆形的轨迹坐标
#include
#include
#include
#include
#pragma comment(lib,"winmm.lib")
//#include 包含头文件
//#pragma comment(lib."文件名称") 包含库文件
constexpr auto WND_WIDTH = 1000;
constexpr auto WND_HEIGHT = 600;
constexpr auto PI = 3.141592653589793238;
constexpr auto NUM = 14;
/***********结构****************/
struct JET //烟花弹
{
int x, y; //发射点坐标
int hx, hy; //最高点坐标 爆炸坐标
int height; //高度 最高点y 发射点y的差值
bool isshoot; //是否发射状态
DWORD t1, t2, dt; //保存时间 时间可以用来描述发射速度
IMAGE img[2]; //保存烟花一明一暗的图片
byte n : 1; //保存烟花弹的明暗状态 位段
//字节为单位 int 4 char 1 n一个位 0-1
}jet[NUM]; //结构体数组13 img这个数组
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];
void welcome();
void init(int i);
void loadimages();
void choice(DWORD& t1);
void shoot();
void Show(DWORD* pMem);
void clss(int a);
void delay(int a);
void detabase(int a);
int main()
{
//res 1.wav
PlaySound(L"sound.dll", NULL, SND_LOOP | SND_FILENAME | SND_ASYNC);
//mp3播放
//mciSendString(L"open 1.mp3 alias bkmusic", NULL, 0, NULL);
//mciSendString(L"play bkmusic repeat", NULL, 0, NULL);
int a;
for (a = 0; a < 5; a++)
{
detabase(a);
delay(100000);
clss(1);
}
delay(500000);
initgraph(WND_WIDTH, WND_HEIGHT); //init初始化 graph图形界面 窗口
srand((unsigned int)time(NULL));
DWORD t1 = timeGetTime();
DWORD* pMem = GetImageBuffer();
//第一个界面
welcome();
//初始化
for (int i = 0; i < NUM; i++)
{
init(i);
}
loadimages();
BeginBatchDraw();
while (!_kbhit())
{
//Sleep(10);
for (int i = 0; i < 1000; i++)
{
for (int j = 0; j < 3; j++)
{
int px1 = rand() % 1000;
int py1 = rand() % 600;
if (py1 < 599)
{
pMem[py1 * 1000 + px1] = pMem[py1 * 1000 + px1 + 1] = BLACK;
}
}
}
choice(t1);
shoot();
Show(pMem);
EndBatchDraw(