@[TOC]

Renderings (with background music)

Project link

Download.csdn.net/download/we…

To make up

Compilation environment: VS2017 & EasyX

If you do not have EasyX, you can download and install it by clicking on the following network disk link, click exe to run it, select your corresponding VS version and click install

Link: pan.baidu.com/s/1pQbktxBd… Extract code: ZA2K copy this section of content after opening Baidu network disk mobile App, operation is more convenient oh — from Baidu network disk super member V4 share

code

The comments are more detailed, so I won’t explain them

#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <graphics.h>  / / header files
#pragma comment(lib,"Winmm.lib")

#define NUM 13

// The structure of the shell
struct Jet
{
	int     x, y;           // The current coordinates
	int     hx, hy;         // The highest point x y
	bool    shoot;          // Whether to launch
	DWORD   t1, t2, dt;     // Launch speed!! T1 t2 launch velocity
	IMAGE   img[2];         // Two small pictures
	byte    n : 1;          // bit segment n is a variable 1 bit.
}jet[NUM];

// The fireworks are captured in the picture
struct Fire
{
	int     r;
	int     max_r;
	int     cen_x, cen_y;   / / circle
	int     x, y;           // Image coordinates in the interface
	int     width, height;  // The width and height of the image
	int     xy[240] [240];   // Pixel matrix

	bool   show;
	bool   draw;
	DWORD  t1, t2, dt;		// Bloom as fast as pixels
}fire[NUM];

void LoadImg(a)
{
	// Image types in EasyX
	IMAGE allflowers, flower;
	loadimage(&allflowers, L"flower.jpg".3120.240);

	for (int i = 0; i < NUM; i++)
	{
		SetWorkingImage(&allflowers);				// Sets the current drawing device to all fireworks
		getimage(&flower, i * 240.0.240.240);	// Capture small fireworks
		SetWorkingImage(&flower);					// Pixels from flower are saved in a 2d array and set to the current drawing device

		for (int x = 0; x < 240; x++)
		{
			for (int y = 0; y < 240; y++)
			{
				fire[i].xy[x][y] = getpixel(x, y);	// Get the color of the point into each small flower matrix
			}
		}
	}

	IMAGE jetImg;  // Image type
	loadimage(&jetImg, L"shoot.jpg".200.50);	
	SetWorkingImage(&jetImg); // Get the small image from jetImg
	/ / 13
	for (int i = 0; i < NUM; i++)
	{
		int n = rand() % 5;  / / 0 to 4
		getimage(&jet[i].img[0], n * 20.0.20.50);
		getimage(&jet[i].img[1], (n + 5) * 20.0.20.50);
	}
	SetWorkingImage(NULL);
}

void GameInit(int n)
{
	// The radius center coordinates of the 13 fireworks
	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 };

	fire[n].cen_x = x[n];
	fire[n].cen_y = y[n];
	fire[n].max_r = r[n];
	fire[n].show = false;
	fire[n].width = 240;
	fire[n].height = 240;
	fire[n].dt = 5;
	fire[n].r = 0;
	fire[n].t1 = GetTickCount(a);// Simply initialize some data
	jet[n].dt = rand() % 10 + 1;  // 1-10ms
	jet[n].n = 0;
	jet[n].t1 = GetTickCount(a); jet[n].shoot =false;
}

// Select smoke bombs
void Chiosejet(DWORD& t1)  // t1 t2 makes the interval between generating new smoke shells.
{
	DWORD t2 = GetTickCount(a);if (t2 - t1 > 100)  // 100ms generates a new smoke shell
	{
		// rand()%13; 0-12
		int n = rand() % NUM;  // Select one at random
		if (jet[n].shoot == false && fire[n].show == false)  // Determine whether to launch or not
		{
			jet[n].x = rand() % 1200;
			jet[n].y = rand() % 100 + 600; / / 600-699
			jet[n].hx = jet[n].x;
			jet[n].hy = rand() % 400;     / / 0-399
			jet[n].shoot = true;            / / selected
			putimage(jet[n].x, jet[n].y, &jet[n].img[jet[n].n], SRCINVERT); } t1 = t2; }}/ / memory
void Shootjet(a)
{
	for (int n = 0; n < NUM; n++)
	{
		jet[n].t2 = GetTickCount(a);if (jet[n].t2 - jet[n].t1 >= jet[n].dt&&jet[n].shoot == true)
		{
			putimage(jet[n].x, jet[n].y, &jet[n].img[jet[n].n], SRCINVERT);
			if (jet[n].y >= jet[n].hy)
			{
				jet[n].y -= 5;  / / up
				jet[n].n++;     / / flashing
			}
			putimage(jet[n].x, jet[n].y, &jet[n].img[jet[n].n], SRCINVERT);

			if (jet[n].y <= jet[n].hy) // Indicates that it has reached its highest point
			{
				putimage(jet[n].x, jet[n].y, &jet[n].img[jet[n].n], SRCINVERT);
				jet[n].shoot = false;
				fire[n].x = jet[n].hx;
				fire[n].y = jet[n].hy;
				fire[n].show = true;
				/ / explosion} jet[n].t1 = jet[n].t2; }}}// Fireworks display
void ShowFire(DWORD* pmem)
{
	int drt[16] = { 5.5.5.5.5.6.25.25.25.25.55.55.55.55.65.65 };

	// Experience is the mother of knowledge
	for (int i = 0; i < NUM; i++)
	{
		fire[i].t2 = GetTickCount(a);if (fire[i].t2 - fire[i].t1 > fire[i].dt&&fire[i].show == true)
		{
			if (fire[i].r <= fire[i].max_r)
			{
				fire[i].r++;
				fire[i].dt = drt[fire[i].r / 10];
				fire[i].draw = true;
			}
			if (fire[i].r >= fire[i].max_r - 1)
			{
				fire[i].draw = false;
				GameInit(i);
			}
			fire[i].t1 = fire[i].t2;
		}

		if (fire[i].draw)
		{
			/ / radian
			for (double a = 0; a <= 6.28; a += 0.01)
			{
				// The parametric equation of a circle
				int x1 = (int)(fire[i].cen_x + fire[i].r*cos(a));
				int y1 = (int)(fire[i].cen_y + fire[i].r*sin(a));

				if (x1 > 0 && x1 < fire[i].width&&y1>0 && y1 < fire[i].height)
				{
					int b = fire[i].xy[x1][y1] & 0xff;
					int g = (fire[i].xy[x1][y1] >> 8) & 0xff;
					int r = fire[i].xy[x1][y1] >> 16;
					// bit operation!

					int xx = (int)(fire[i].x + fire[i].r*cos(a));
					int yy = (int)(fire[i].y + fire[i].r*sin(a));

					if (b > 0x20 && g > 0x20 && r > 0x20 && xx > 0 && xx < 1200 && yy>0 && yy < 800)
					{
						pmem[yy * 1200 + xx] = BGR(fire[i].xy[x1][y1]);
					}
				}
			}
			fire[i].draw = false; }}}int main(a)
{
	// Initialize the graphical interface to open a window. 1200, 800,
	initgraph(1200.800);        / / 1200 * 800
	mciSendString(L"open small luck. mp3 alias BGM".0.0.0);
	mciSendString(L"play bgm".0.0.0);

	DWORD t1 = GetTickCount(a); DWORD *pmem =GetImageBuffer(a);// Get the graphics memory pointer of the drawing device
	// Seeds for random numbers
	srand((unsigned int)time(NULL));
	// Handle loading images
	LoadImg(a);for (int i = 0; i < NUM; i++)
	{
		GameInit(i);
	}
	BeginBatchDraw(a);// Start batch drawing
	while (1)
	{
		Chiosejet(t1);
		Shootjet(a);ShowFire(pmem);
		FlushBatchDraw(a); }return 0;
}

Copy the code