C/C++の圖形界面編程打造——浪漫的表白程序!

誰(shuí)說(shuō)程序員不浪漫???來(lái)來(lái)來(lái)一起打造一個(gè)浪漫的表白程序,配上好聽(tīng)的音樂(lè),瞬間高大上。


下面,發(fā)下代碼吧,昨天的憤怒的小鳥(niǎo)推箱子版本的沒(méi)發(fā),今天發(fā)這個(gè),,,簡(jiǎn)單的C語(yǔ)言和easyx一起打造浪漫的程序附帶上注釋吧

#include

#include

#include

#include

#include

#include

#pragma comment ( lib, "Winmm.lib" )

/***** 宏定義區(qū) ******/

#define NUM13// 煙花種類(lèi)數(shù)量宏定義

#define PI 3.1415926548

/***** 結(jié)構(gòu)定義區(qū) **********/

// 煙花結(jié)構(gòu)

struct FIRE

{

int r;// 當(dāng)前爆炸半徑

int max_r;// 爆炸中心距離邊緣最大半徑

int x, y;// 爆炸中心在窗口的坐標(biāo)

int cen_x, cen_y;// 爆炸中心相對(duì)圖片左上角的坐標(biāo)

int width, height;// 圖片的寬高

int xy[240][240];// 儲(chǔ)存圖片像素點(diǎn)

bool show;// 是否綻放

bool draw;// 開(kāi)始輸出像素點(diǎn)

DWORD t1, t2, dt;// 綻放速度

}Fire[NUM];

// 煙花彈結(jié)構(gòu)

struct JET

{

int x, y;// 噴射點(diǎn)坐標(biāo)

int hx, hy;// 最高點(diǎn)坐標(biāo)------將賦值給 FIRE 里面的 x, y

int height;// 煙花高度

bool shoot;// 是否可以發(fā)射

DWORD t1, t2, dt;// 發(fā)射速度

IMAGE img[2];// 儲(chǔ)存花彈一亮一暗圖片

byte n : 1;// 圖片下標(biāo)

}Jet[NUM];

/**** 函數(shù)申明區(qū) ****/

void welcome();

void Init(int);// 初始化煙花

void Load();// 加載煙花圖片

void Shoot();// 發(fā)射煙花

void Chose(DWORD&);// 篩選煙花

void Style(DWORD&);// 發(fā)射樣式

void Show(DWORD*);// 綻放煙花

// 主函數(shù)

void main()

{

initgraph(1200, 800);

srand(time(0));

// 播放背景音樂(lè)

mciSendString("open ./fire/小幸運(yùn).mp3 alias bk", 0, 0, 0);

mciSendString("play bk repeat", 0, 0, 0);

welcome();

DWORD t1 = timeGetTime();// 篩選煙花計(jì)時(shí)

DWORD st1 = timeGetTime();// 播放花樣計(jì)時(shí)

DWORD* pMem = GetImageBuffer();// 獲取窗口顯存指針

for (int i = 0; i < NUM; i++)// 初始化煙花

{

Init(i);

}

Load();// 將煙花圖片信息加載進(jìn)相應(yīng)結(jié)構(gòu)中

BeginBatchDraw();// 開(kāi)始批量繪圖

while (!kbhit())

{

Sleep(10);

// 隨機(jī)選擇 4000 個(gè)像素點(diǎn)擦除

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

{

for (int j = 0; j < 2; j++)

{

int px1 = rand() % 1200;

int py1 = rand() % 800;

if (py1 < 799)// 防止越界

pMem[py1 * 1200 + px1] = pMem[py1 * 1200 + px1 + 1] = BLACK;// 對(duì)顯存賦值擦出像素點(diǎn)

}

}

Chose(t1);// 篩選煙花

Shoot();// 發(fā)射煙花

Show(pMem);// 綻放煙花

Style(st1);// 花樣發(fā)射

FlushBatchDraw();// 顯示前面的所有繪圖操作

}

}

void welcome()

{

//setfillstyle(0);

setcolor(YELLOW);

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

{

int x = 600 + int(180 * sin(PI * 2 * i / 60));

int y = 200 + int(180 * cos(PI * 2 * i / 60));

cleardevice();

settextstyle(i, 0, "楷體");

outtextxy(x, y, "雙十一,不剁手!");

outtextxy(x-130, y+100, "寫(xiě)段代碼送女友!");

Sleep(25);

}

getchar();

cleardevice();

settextstyle(25, 0, "楷體");

outtextxy(400, 200, "原來(lái)你是我最想留住的幸運(yùn)");

outtextxy(400, 250, "原來(lái)我們和愛(ài)情曾經(jīng)靠得那么近");

outtextxy(400, 300, "那為我對(duì)抗世界的決定");

outtextxy(400, 350, "那陪我淋的雨");

outtextxy(400, 400, "一幕幕都是你");

outtextxy(400, 450, "一塵不染的真心。");

outtextxy(600, 500, "----《小幸運(yùn)》");

getchar();


推薦一個(gè)學(xué)C語(yǔ)言/C++的學(xué)習(xí)裙【567625668 】,無(wú)論你是大牛還是小白,是想轉(zhuǎn)行還是想入行都可以來(lái)了解一起進(jìn)步一起學(xué)習(xí)!裙內(nèi)有開(kāi)發(fā)工具,很多干貨和技術(shù)資料分享!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容