最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網 會員登陸 & 注冊

用c++表達生日祝福丨生日歌+煙花代碼

2023-07-22 10:18 作者:MnAg同學  | 我要投稿

完整代碼


# include<graphics.h>

#include<time.h>

#include<stdlib.h>

#include<stdio.h>

#include<math.h>

#include<Windows.h>

#pragma commet(lib,"winmm.lib")

#define NUM 10??//煙花彈個數

#define PI 3.1415926?

# define L1?262??//定義音調

# define sL1 277

# define L2?294

# define sL2 311

# define L3?300

# define L4?349

# define sL4 370

# define L5?392

# define sL5 415

# define L6?440

# define sL6 466

# define L7?494

# define M1?523

# define sM1 554

# define M2?587

# define sM2 622

# define M3?659

# define M4?698

# define sM4 740

# define M5?784

# define sM5 831

# define M6?880

# define sM6 932

# define M7?988

# define H1?1046

# define sH1 1109

# define H2?1175

# define sH2 1245

# define H3?1318

# define H4?1397

# define sH4 1480

# define H5?1568

# define sH5 1661

# define H6?1760

# define sH6 1865

# define H7?1976

# define K??0

# define d1?222

# define d2?444

# define d3?888


void FireInit(int);

void Load();

void Shoot();

void ChoiceJet(DWORD&);

void ShowFire(DWORD*);


//煙花彈

struct jet{

int x,y;?????//煙花彈坐標

int hx,hy;????//最高點坐標

bool shoot;????//煙花彈是否處于發(fā)射狀態(tài)

DWORD t1,t2,dt;??//發(fā)射時間 引爆時間 間隔時間

IMAGE img[2];???//2張圖片 一明一暗 01下標

byte n: 1;????//C結構體 位段?

}jet[NUM];??????//煙花彈個數


//煙花

struct Fire{

int x,y;?????//煙花的坐標

int r;??????//煙花的半徑

int max_r;????//最大半徑

int cen_x,cen_y;?//中心距左上角的距離

int width,height; //長寬

int xy[240][240]; //像素 矩陣

bool draw;????//畫出

bool show;????//顯示

DWORD t1,t2,dt;??//發(fā)射時間 引爆時間 隔離時間

}fire[NUM];


//初始化函數

void FireInit(int i){

//初始化煙花彈

jet[i].t1=GetTickCount();

jet[i].shoot=false;

jet[i].dt=10;

jet[i].n=0;

fire[i].show=false;

fire[i].r=0;

fire[i].dt=5;

fire[i].t1=GetTickCount();

fire[i].max_r=rand()%50+100;

fire[i].cen_x=rand()%30+80;

fire[i].cen_y=rand()%30+80;

fire[i].width=240;

fire[i].height=240;

}


//加載

void Load(){

//加載煙花彈

IMAGE jeting;

loadimage(&jeting,L"E:/mypro/fire/shoot.jpg",200,50);

SetWorkingImage(&jeting);

for(int i=0;i<NUM;i++){

int n=rand()%5;

getimage(&jet[i].img[0],n*20,0,20,50);

getimage(&jet[i].img[1],(n+5)*20,0,20,50);

}

SetWorkingImage(NULL);

//加載煙花

IMAGE fireimage,Fireimage;

loadimage(&Fireimage,L"E:/mypro/fire/flower.jpg",3120,240);

for(int i=0;i<NUM;i++){

SetWorkingImage(&Fireimage);

getimage(&fireimage,i*240,0,240,240);

SetWorkingImage(&fireimage);

for(int a=0;a<240;a++){

for(int b=0;b<240;b++){

fire[i].xy[a][b]=getpixel(a,b);

}

}

}

SetWorkingImage(NULL);

}


//選擇煙花彈

void ChoiceJet(DWORD&t1){

DWORD t2=GetTickCount();

if(t2-t1>100) //煙花彈出現(xiàn)的時間間隔100ms

{

//煙花彈個數

int i=rand()%10;

//不處于發(fā)射狀態(tài)

if (i<10 && jet[i].shoot==false && fire[i].show==false)

{

//煙花彈

jet[i].x=rand()%1000;

jet[i].y=rand()%100+450;

jet[i].hx=jet[i].x;

jet[i].hy=rand()%300; //0-299

jet[i].shoot=true; //發(fā)射狀態(tài)


putimage(jet[i].x,jet[i].y,&jet[i].img[jet[i].n],SRCINVERT);

}

t1=t2;

}

}


//判斷發(fā)射

void Shoot()

{

for(int i=0;i<NUM;i++){

jet[i].t2=GetTickCount();

if(jet[i].t2-jet[i].t1>=jet[i].dt && jet[i].shoot==true){

putimage(jet[i].x,jet[i].y,&jet[i].img[jet[i].n],SRCINVERT);

if(jet[i].y>=jet[i].hy){

jet[i].n++; //閃爍

jet[i].y-=5;

}

putimage(jet[i].x,jet[i].y,&jet[i].img[jet[i].n],SRCINVERT);


if(jet[i].y<=jet[i].hy){

putimage(jet[i].x,jet[i].y,&jet[i].img[jet[i].n],SRCINVERT);

jet[i].shoot=false;

//達到最大高度,接下來交給煙花

//重新發(fā)射

fire[i].x=jet[i].hx;

fire[i].y=jet[i].hy;

fire[i].show=true;

}

}

jet[i].t1=jet[i].t2;

}

}


//顯示煙花

void ShowFire(DWORD*pMem)

{

int drt[16]={5,5,5,5,5,10,25,25,25,25,55,55,55,55,55,65};


for(int i=0;i<NUM;i++)

{

fire[i].t2=GetTickCount();

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;

FireInit(i);

}

fire[i].t1=fire[i].t2;

//如果該號炮花可爆炸,根據當前爆炸半徑畫煙花,顏色值接近黑色的不輸出

if (fire[i].draw)

{

for(double a=0;a<=6.28;a+=0.01)

{

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);

//煙花像素點在窗口上的坐標

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

int yy=(int)(fire[i].y-fire[i].r*sin(a));

//較暗的像素點不輸出,防止越界

if(r>0x20 && g>0x20 && b>0x20 && xx>0 && xx<1000 && yy>0 && yy<600)

{

pMem[yy*1000+xx]=BGR(fire[i].xy[x1][y1]);

}

fire[i].draw=false;

}

}

}

}

}

}


//主函數

int main()

{

//初始界面(1000,600)

initgraph(1000,600);

//初始化種子

srand((unsigned int)time(NULL));

DWORD t1=GetTickCount();

DWORD t2=GetTickCount();

DWORD*pMem=GetImageBuffer();

Beep(M1,d2); //祝你生日快樂

Beep(M1,d2);

Beep(M2,d3);

Beep(M1,d3);

Beep(M4,d3);

Beep(M3,d3+d3);

Beep(M1,d2); //祝你生日快樂

Beep(M1,d2);

Beep(M2,d3);

Beep(M1,d3);

Beep(M5,d3);

Beep(M4,d3+d3);

Beep(M1,d3); //祝你生日快樂

Beep(M1,d3);

Beep(H1,d3);

Beep(M6,d3);

Beep(M4,d3);

Beep(M3,d3);

Beep(M2,d3);

Beep(M7,d3+d1); //祝你生日快樂

Beep(M7,d2);

Beep(M6,d3);

Beep(M4,d3);

Beep(M5,d3);

Beep(M4,d3+d3);

for(int i=0;i<NUM;i++)

{

FireInit(i);

}

Load();

BeginBatchDraw();

while(1)

{

//隨機選擇像素點擦除

for(int clr=0;clr<200;clr++)

{

int px1=rand()%1000;

int py1=rand()%600;


//防止越界

if(py1<599)

{

//對顯存賦值擦除像素點

pMem[py1*1000+px1]=pMem[py1*1000+px1+1]=BLACK;

}

}

ChoiceJet(t1);

Shoot();

ShowFire(pMem);

FlushBatchDraw();

}

system("pause");

return 0;

}






用c++表達生日祝福丨生日歌+煙花代碼的評論 (共 條)

分享到微博請遵守國家法律
杂多县| 耿马| 万安县| 肃宁县| 谢通门县| 白银市| 靖宇县| 肥西县| 德清县| 辽阳市| 乌兰浩特市| 金湖县| 汉沽区| 江城| 潮州市| 栖霞市| 黑龙江省| 井陉县| 察隅县| 乌兰浩特市| 陆良县| 柳江县| 广德县| 峨边| 老河口市| 锡林郭勒盟| 延津县| 莱州市| 涟源市| 会昌县| 工布江达县| 任丘市| 来宾市| 榆社县| 莒南县| 区。| 万年县| 酒泉市| 凤翔县| 准格尔旗| 织金县|