七夕女友礼物

*七夕来袭!是时候展现专属于程序员的浪漫了!

代码函数

在这里插入图片描述
在这里插入图片描述在这里插入图片描述

直接上代码,就不讲解了,毕竟是送个女友的


#include <stdio.h>
#include <conio.h>
#include <easyx.h>
#include<mmsystem.h>
#include <graphics.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <cmath>
#include <Windows.h>
#pragma comment (lib, "WS2_32.lib")
#pragma comment(lib,"winmm.lib")

#define SNOW_COUNT_MAX 200
#define SERVER_PORT  2021
#define MUN 10
#define NUM 13
#define PI 3.1415
#define WIDTH 1200
#define HEIGHT 800

IMAGE img_bk[3];
IMAGE img_meteor[3];
IMAGE jetImg;
DWORD* pMem;
IMAGE love;




//流星结构体
struct Meteor //流星
{
	int x;
	int y;
	int speed;//速度
};


struct Meteor meteor[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
{
	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];



void putimagePNG(int  picture_x, int picture_y, IMAGE* picture);
int getDelay();
void putimagePNG2(int x, int y, IMAGE* picture);



int getDelay() {
	static unsigned long long lastTime = 0;
	unsigned long long currentTime = GetTickCount();
	if (lastTime == 0) 
	{
		lastTime = currentTime;
		return 0;
	}

	else 
	{
		int ret = currentTime - lastTime;
		lastTime = currentTime;
		return ret;
	}
}


// 载入PNG图并去透明部分
void putimagePNG(int  picture_x, int picture_y, IMAGE* picture) //x为载入图片的X坐标,y为Y坐标
{
	DWORD* dst = GetImageBuffer();    // GetImageBuffer()函数,用于获取绘图设备的显存指针,EASYX自带
	DWORD* draw = GetImageBuffer();
	DWORD* src = GetImageBuffer(picture); //获取picture的显存指针
	int picture_width = picture->getwidth(); //获取picture的宽度,EASYX自带
	int picture_height = picture->getheight(); //获取picture的高度,EASYX自带
	int graphWidth = getwidth();       //获取绘图区的宽度,EASYX自带
	int graphHeight = getheight();     //获取绘图区的高度,EASYX自带
	int dstX = 0;    //在显存里像素的角标

	// 实现透明贴图 公式: Cp=αp*FP+(1-αp)*BP , 贝叶斯定理来进行点颜色的概率计算
	for (int iy = 0; iy < picture_height; iy++)
	{
		for (int ix = 0; ix < picture_width; ix++)
		{
			int srcX = ix + iy * picture_width; //在显存里像素的角标
			int sa = ((src[srcX] & 0xff000000) >> 24); //0xAArrggbb;AA是透明度
			int sr = ((src[srcX] & 0xff0000) >> 16); //获取RGB里的R
			int sg = ((src[srcX] & 0xff00) >> 8);   //G
			int sb = src[srcX] & 0xff;              //B
			if (ix >= 0 && ix <= graphWidth && iy >= 0 && iy <= graphHeight && dstX <= graphWidth * graphHeight)
			{
				dstX = (ix + picture_x) + (iy + picture_y) * graphWidth; //在显存里像素的角标
				int dr = ((dst[dstX] & 0xff0000) >> 16);
				int dg = ((dst[dstX] & 0xff00) >> 8);
				int db = dst[dstX] & 0xff;
				draw[dstX] = ((sr * sa / 255 + dr * (255 - sa) / 255) << 16)  //公式: Cp=αp*FP+(1-αp)*BP  ; αp=sa/255 , FP=sr , BP=dr
					| ((sg * sa / 255 + dg * (255 - sa) / 255) << 8)         //αp=sa/255 , FP=sg , BP=dg
					| (sb * sa / 255 + db * (255 - sa) / 255);              //αp=sa/255 , FP=sb , BP=db
			}
		}
	}
}

// 适用于 y <0 以及x<0的任何情况
void putimagePNG2(int x, int y, IMAGE* picture) 

{
	IMAGE imgTmp;
	if (y < 0) 
	{
		SetWorkingImage(picture);
		getimage(&imgTmp, 0, -y,
			picture->getwidth(), picture->getheight() + y);
		SetWorkingImage();
		y = 0;
		picture = &imgTmp;
	}

	if (x < 0)
	{
		SetWorkingImage(picture);
		getimage(&imgTmp, -x, 0, picture->getwidth() + x, picture->getheight());
		SetWorkingImage();
		x = 0;
		picture = &imgTmp;
	}

	putimagePNG(x, y, picture);

}

// 适用于 y <0 以及y>0的任何情况
void putimagePNG2(int x, int y, int winWidth, IMAGE* picture)
{
	IMAGE imgTmp;
	if (y < 0) 
	{
		SetWorkingImage(picture);
		getimage(&imgTmp, 0, -y,
			picture->getwidth(), picture->getheight() + y);
		SetWorkingImage();
		y = 0;
		picture = &imgTmp;
	}

	if (x < 0) 
	{
		SetWorkingImage(picture);
		getimage(&imgTmp, -x, 0, picture->getwidth() + x, picture->getheight());
		SetWorkingImage();
		x = 0;
		picture = &imgTmp;
	}
	else if (x >= winWidth)
	{
		return;
	}
	else if (x > winWidth - picture->getwidth()) 
	{
		SetWorkingImage(picture);
		getimage(&imgTmp, 0, 0, winWidth - x, picture->getheight());
		SetWorkingImage();
		picture = &imgTmp;
	}

	putimagePNG(x, y, picture);
}

// 适用于 y <0 以及y>0的任何情况
void putimagePNG2(int x, int y, int winWidth, int winHeight, IMAGE* picture) 
{
	IMAGE imgTmp;
	if (y < 0) 
	{
		SetWorkingImage(picture);
		getimage(&imgTmp, 0, -y,
			picture->getwidth(), picture->getheight() + y);
		SetWorkingImage();
		y = 0;
		picture = &imgTmp;
	}
	else if (y > winHeight - picture->getheight())
	{
		SetWorkingImage(picture);
		getimage(&imgTmp, 0, 0,
			picture->getwidth(), winHeight - y);
		SetWorkingImage();

		picture = &imgTmp;
	}

	if (x < 0) 
	{
		SetWorkingImage(picture);
		getimage(&imgTmp, -x, 0, picture->getwidth() + x, picture->getheight());
		SetWorkingImage();
		x = 0;
		picture = &imgTmp;
	}
	else if (x >= winWidth) 
	{
		return;
	}

	else if (x > winWidth - picture->getwidth()) 
	{
		SetWorkingImage(picture);
		getimage(&imgTmp, 0, 0, winWidth - x, picture->getheight());
		SetWorkingImage();
		picture = &imgTmp;
	}

	putimagePNG(x, y, picture);
}



void  preLoadSound(const char* name) 
{
	char cmd[512];

	sprintf_s(cmd, sizeof(cmd), "open %s alias %s-1", name, name);

	mciSendString(cmd, 0, 0, 0);

	sprintf_s(cmd, sizeof(cmd), "open %s alias %s-2", name, name);

	mciSendString(cmd, 0, 0, 0);

}

void  playSound(const char* name)
{
	static int index = 1;
	char cmd[512];

	if (index == 1) 
	{
		sprintf_s(cmd, sizeof(cmd), "play %s-1", name);
		mciSendString(cmd, 0, 0, 0);
		sprintf_s(cmd, sizeof(cmd), "close %s-2", name);
		mciSendString(cmd, 0, 0, 0);
		sprintf_s(cmd, sizeof(cmd), "open %s alias %s-2", name, name);
		mciSendString(cmd, 0, 0, 0);
		index++;
	}
	else if (index == 2)
	{
		sprintf_s(cmd, sizeof(cmd), "play %s-2", name);

		mciSendString(cmd, 0, 0, 0);

		sprintf_s(cmd, sizeof(cmd), "close %s-1", name);

		mciSendString(cmd, 0, 0, 0);
		sprintf_s(cmd, sizeof(cmd), "open %s alias %s-1", name, name);
		mciSendString(cmd, 0, 0, 0);
		index = 1;
	}
}










// 载入PNG图并去透明部分
void initMeteor(int i)//初始化流星
{
	meteor[i].x = rand() % (1200 * 2) - 1200;//(0~-1000,1200)
	meteor[i].y = rand() % 20 - 200; //(-78,-200)
	meteor[i].speed = rand() % 2 + 1;
}

 
void drawMeteor()//画流星
{
	for (int i = 0; i < NUM; i++)
	{
		putimage(meteor[i].x, meteor[i].y, img_meteor, SRCPAINT);
	}
}

void moveMeteor()//移动流星
{
	//改变坐标就可以实现移动,斜线x,y都要变化
	for (int i = 0; i < NUM; i++)
	{
		meteor[i].x += meteor[i].speed;
		meteor[i].y += meteor[i].speed;
		if (meteor[i].y > getheight() || meteor[i].x > getwidth())
		{
			initMeteor(i);
		}
	}
}


void welcome()
{
	int s = 0;
	mciSendString("open ./images/1.mp3 alias bgm ", 0, 0, 0);
	mciSendString("play bgm", 0, 0, 0);
	settextstyle(40, 0, "华文行楷");
	setbkmode(TRANSPARENT);
	for (s = 0; s <= 15; s++)
	{

		cleardevice();
		putimage(0, 0, img_bk);
		outtextxy(450, 20,	"送给你");
		settextstyle(40, 0, "华文行楷");
		outtextxy(200, 100, "成长的岁月里有快乐");
		outtextxy(200, 150, "前进的道路上有花朵");
		outtextxy(200, 200, "越来越美丽"); 
		outtextxy(200, 250, "岁岁涌今朝");
		outtextxy(200, 300, "天生旧物不如新");
		outtextxy(200, 350,	"玲珑骰子安红豆");
		outtextxy(200, 400, "入骨相思知不知");
		settextcolor(RGB(rand() % 256, rand() % 256, rand() % 256, ));

		for (size_t i = 0; i < 30; i++)
		{
			settextcolor(RGB(rand() % 256, rand() % 256, rand() % 256, rand()));
			 
			
			putimagePNG2 (rand() % 1200, rand() % 800,1200,800, &love);
		}
		Sleep(500);
	}

	rewind(stdin);
	//mciSendString("close bgm", 0, 0, 0);
	
}

// 初始化指定的烟花和烟花弹
void initFire(int i)
{
	// 分别为:烟花中心到图片边缘的最远距离、烟花中心到图片左上角的距离 (x、y) 两个分量
	int r[13] = { 120, 120, 155, 123, 130, 147, 138, 138, 130, 135, 140, 132, 155 };
	int x[13] = { 120, 120, 110, 117, 110, 93, 102, 102, 110, 105, 100, 108, 110 };
	int y[13] = { 120, 120, 85, 118, 120, 103, 105, 110, 110, 120, 120, 104, 85 };

	/**** 初始化烟花 *****/
	fires[i].x = 0;				// 烟花中心坐标
	fires[i].y = 0;
	fires[i].width = 240;				// 图片宽
	fires[i].height = 240;				// 图片高
	fires[i].max_r = r[i];				// 最大半径
	fires[i].cent2LeftTopX = x[i];				// 中心距左上角距离
	fires[i].cent2LeftTopY = y[i];
	fires[i].show = false;			// 是否绽放
	fires[i].dt = 5;				// 绽放时间间隔
	fires[i].t1 = timeGetTime();
	fires[i].r = 0;				// 从 0 开始绽放
	fires[i].draw = false;

	/**** 初始化烟花弹 *****/
	//timeGetTime 该时间为从系统开启算起所经过的时间,单位:毫秒
	bullets[i].t1 = timeGetTime();
	bullets[i].dt = rand() % 10;		// 发射速度时间间隔
	bullets[i].n = 0;				// 烟花弹闪烁图片下标
	bullets[i].shoot = false;			// 是否发射
}



// 加载图片
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 drawFire(int i)
{
	if (!fires[i].draw) 
	{
		return;
	}

	// 弧度 PI 3.14  2PI 6.28  360度
	for (double a = 0; a <= 6.28; a += 0.01)  //0-2PI 弧度
	{
		//三角函数
		int x1 = (int)(fires[i].cent2LeftTopX + fires[i].r * cos(a));	// 相对于图片左上角的坐标
		int y1 = (int)(fires[i].cent2LeftTopY - fires[i].r * sin(a));   // 方向和easyx的Y坐标相反

		if (x1 > 0 && x1 < fires[i].width && y1 > 0 && y1 < fires[i].height)	// 只输出图片内的像素点
		{
			int b = fires[i].pix[x1][y1] & 0xff;  //得到三原色的最低字节(B)
			int g = (fires[i].pix[x1][y1] >> 8) & 0xff; //第2个字节
			int r = (fires[i].pix[x1][y1] >> 16);

			// 烟花像素点在窗口上的坐标
			int xx = (int)(fires[i].x + fires[i].r * cos(a));
			int yy = (int)(fires[i].y - fires[i].r * sin(a));

			// 较暗的像素点不输出、防止越界
			//二维数组  当成 一位数组使用的案例 
			//颜色值接近黑色的不输出。
			// 看电影  5排第6个座位: 5*30+6
			if (r > 0x20 && g > 0x20 && b > 0x20 && xx > 0 && xx < 1200 && yy > 0 && yy < 800)
			{
				pMem[yy * 1200 + xx] = BGR(fires[i].pix[x1][y1]);	// 显存操作绘制烟花

			}
				
		}
	}
	fires[i].draw = false;
}




// C++的引用
void chose(DWORD t1) //t1位为上一次点烟花弹的时间
{
	DWORD t2 = timeGetTime();

	if (t2 - t1 > 100) // 100ms点一次
	{
		int n = rand() % 30; //取摸的数字越大,烟花发射频率越慢,因为<13的概率就越低

		if (n < 13 && bullets[n].shoot == false && fires[n].show == false)
		{
			/**** 重置烟花弹,预备发射 *****/
			bullets[n].x = rand() % 1200;
			bullets[n].y = rand() % 100 + 600; // 600-699
			bullets[n].topX = bullets[n].x;
			bullets[n].topY = rand() % 400; // 0.399
			bullets[n].height = bullets[n].y - bullets[n].topY;
			bullets[n].shoot = true;

			// 绘制烟花的初始状态(即:在起始位置绘制烟花)
			putimage(bullets[n].x, bullets[n].y, &bullets[n].img[bullets[n].n], SRCINVERT);

			/**** 播放每个烟花弹的声音 *****/
			char cmd[50];
			sprintf_s(cmd, "play s%d", n);
			mciSendString(cmd, 0, 0, 0);
		}
		t1 = t2;
	}
}


// 项目初始化
void init() 
{
	// 创建窗口
	initgraph(1200, 800);

	// 播放背景音乐
	mciSendString("play fire/ring.mp3 repeat", 0, 0, 0);

	for (int i = 0; i < NUM; i++)
	{	// 初始化烟花和烟花弹
		initFire(i);
	}

	loadFireImages();

	// 这个函数用于获取绘图设备的显示缓冲区指针。
	pMem = GetImageBuffer();		// 获取窗口显存指针


	// 打开音效并设置别名
	char cmd[128];
	for (int i = 0; i < 13; i++) 
	{
		sprintf_s(cmd, sizeof(cmd), "open fire/shoot.mp3 alias s%d", i);
		mciSendString(cmd, 0, 0, 0); // 打开13次

		sprintf_s(cmd, sizeof(cmd), "open fire/bomb.wav alias f%d", i);
		mciSendString(cmd, 0, 0, 0); // 打开13次
	}

 
}


void clearImage() 
{
	for (int i = 0; i < 2000; i++)
	{
		int px1 = rand() % 1200; // 0..1199
		int py1 = rand() % 800;  // 0.799

		pMem[py1 * 1200 + px1] = BLACK;
		pMem[py1 * 1200 + px1 + 1] = BLACK;	// 对显存赋值擦出像素点		
	}

}

// 烟花弹升空
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_s(c1, "close s%d", i);
				sprintf_s(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;
		}
	}
}

// 绽放烟花
void showFire() 
{
	// 烟花个阶段绽放时间间隔,制作变速绽放效果
	// 为什么数组大小定义为16?
	// 目前烟花的最大半径是155,准备以半径/10可刻度,不同的半径,绽放速度不同
	// 半径越大,绽放越慢
	//              10 20 30 40 50 
	int drt[16] = { 5, 5, 5, 5, 5, 6, 25, 25, 25, 25, 55, 55, 55, 55, 55 };

	for (int i = 0; i < NUM; i++) 
	{
		fires[i].t2 = timeGetTime();

		// 增加爆炸半径,绽放烟花,增加时间间隔做变速效果
		if (fires[i].t2 - fires[i].t1 > fires[i].dt
			&& fires[i].show == true)
		{
			// 更新烟花半径
			if (fires[i].r < fires[i].max_r) 
			{
				fires[i].r++;
				fires[i].dt = drt[fires[i].r / 10];
				fires[i].draw = true;
			}

			// 销毁烟花,并重新初始化该序号的飞弹和烟花
			if (fires[i].r >= fires[i].max_r) 
			{
				fires[i].draw = false;
				initFire(i);

				// 关闭爆炸音效,并重新打开爆炸音效
				char cmd[64];
				sprintf_s(cmd, "close f%d", i);
				mciSendString(cmd, 0, 0, 0);

				sprintf_s(cmd, sizeof(cmd), "open fire/bomb.wav alias f%d", i);
				mciSendString(cmd, 0, 0, 0);
			}

			// 更新烟花的时间
			fires[i].t1 = fires[i].t2;
		}

		// 绘制指定的烟花
		drawFire(i);
	}
}

void heartFire(DWORD& st1)
{
	DWORD st2 = timeGetTime();

	static bool flag = false;
	static DWORD startTime = 0;

	 

	if (st2 - st1 > 20000)		// 20秒
	{
		flag = true;
		startTime = timeGetTime();
		// 先擦除正在发送的烟花弹
		for (int i = 0; i < 13; i++) {
			if (bullets[i].shoot)
				putimage(bullets[i].x, bullets[i].y, &bullets[i].img[bullets[i].n], SRCINVERT);
		}


		// 心形坐标
		int x[13] = { 600, 750, 910, 1000, 950, 750, 600, 450, 250, 150, 250, 410, 600 };
		int y[13] = { 650, 530, 400, 220, 50, 40, 200, 40, 50, 220, 400, 530, 650 };
		for (int i = 0; i < NUM; i++)
		{
			bullets[i].x = x[i];
			bullets[i].y = y[i] + 750;  //每个烟花弹的发射距离都是750,确保同时爆炸
			bullets[i].topX = x[i];
			bullets[i].topY = y[i];


			bullets[i].height = bullets[i].y - bullets[i].topY;
			bullets[i].shoot = true;
			bullets[i].dt = 7;
			// 显示烟花弹
			putimage(bullets[i].x, bullets[i].y, &bullets[i].img[bullets[i].n], SRCINVERT);

			/**** 设置烟花参数 ***/
			fires[i].x = bullets[i].x + 10;
			fires[i].y = bullets[i].topY;
			fires[i].show = false;
			fires[i].r = 0;


		}
		st1 = st2;
	}
}


void daoJiShi() 
{
	IMAGE img[6];
	char name[64];
	for (int i = 0; i < 6; i++) {
		sprintf(name, "fire/%d.png", i);
		loadimage(&img[i], name);
	}

	for (int i = 5; i >= 0; i--) {
		BeginBatchDraw();
		cleardevice();
		putimage((1200 - img[i].getwidth()) / 2, (800 - img[i].getheight()) / 2, &img[i]);
		EndBatchDraw();
		Sleep(1000);
	}
	cleardevice();
	rewind(stdin);
}



			



int main()
{
	initgraph(1200, 800);
	srand((unsigned)time(NULL) + clock());
	loadimage(img_bk,"./images/4.jpeg",1200, 800,true);
	loadimage(img_bk+1, "./images/9.jpeg", 1200, 800);
	loadimage(img_bk + 2, "./images/4.jpeg", 1200, 800);
	loadimage(img_meteor,"./images/d.jpeg", 50,50);
	loadimage(&love, "./images/123.png", 50, 50);
	welcome();

	
	mciSendString("close bgm", 0, 0, 0);
	cleardevice();
	init();

	DWORD t1 = timeGetTime();	// 筛选烟花计时
	DWORD ht1 = timeGetTime();  // 播放花样计时
	DWORD* pMem = GetImageBuffer();//获取窗口的内存指针

	BeginBatchDraw();
	daoJiShi();
	settextstyle(40, 0, "华文行楷");
	setcolor(YELLOW);
	outtextxy(450, 30, "Firework");
	Sleep(500);
	cleardevice();
	fflush(stdin);
	
	

	while (!_kbhit())
	 
	{	
			// 帧等待
			Sleep(10);
			clearImage();
			chose(t1); //点火
			shoot(); //升空
			showFire();
			heartFire(ht1);
			FlushBatchDraw();	// 显示前面的所有绘图操作
		 

	}
	mciSendString("close fire/ring.mp3 ", 0, 0, 0);

	mciSendString("open ./images/bk1.mp3 alias bgm2 ", 0, 0, 0);
	mciSendString("play bgm2", 0, 0, 0);
		setbkmode(TRANSPARENT);
		for (size_t i = 0; i < NUM; i++)
		{
			initMeteor(i);
		}
		//防止闪屏 双缓冲
		BeginBatchDraw();//开起双缓冲绘图
		while (true)
		{
			int begin = clock();//获取程序运行时间(毫秒数)
			//控制画面的帧数 26
			putimage(0, 0, img_bk + 1);
			drawMeteor();
			moveMeteor();
			FlushBatchDraw();//刷星
			//获取程序总共的执行时间
			int timeRemaining = clock() - begin;
			//计算每帧需要的时间
			int timeFrame = 1000.0 / 60;
			//获取程序执行时间有没有超过,没帧执行的最大时间
			int delay = timeFrame - timeRemaining;
			if (delay > 0)
			{
				Sleep(delay);//动态变化
			}
		}
		cleardevice();
		EndBatchDraw();
		mciSendString("close bgm2", 0, 0, 0);
		getchar();

		return 0;
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

luciferau

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值