C語言和圖形界面編程打造——浪漫的表白程序

誰說程序員不浪漫???來來來一起打造一個浪漫的表白程序,配上好聽的音樂,瞬間高大上。

下面,發下代碼吧,昨天的憤怒的小鳥推箱子版本的沒發,今天發這個,,,簡單的C語言和easyx一起打造浪漫的程序附帶上注釋吧

#include

#include

#include

#include

#include

#include

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

/***** 宏定義區 ******/

#define NUM13// 煙花種類數量宏定義

/***** 結構定義區 **********/

// 煙花結構

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

// 煙花彈結構

struct JET

{

int x, y;// 噴射點坐標

int hx, hy;// 最高點坐標------將賦值給 FIRE 里面的 x, y

int height;// 煙花高度

bool shoot;// 是否可以發射

DWORD t1, t2, dt;// 發射速度

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

byte n : 1;// 圖片下標

}Jet[NUM];

/**** 函數申明區 ****/

void welcome();

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

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

void Shoot();// 發射煙花

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

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

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

// 主函數

void main()

{

initgraph(1200, 800);

srand(time(0));

// 播放背景音樂

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

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

welcome();

DWORD t1 = timeGetTime();// 篩選煙花計時

DWORD st1 = timeGetTime();// 播放花樣計時

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

for (int i = 0; i

{

Init(i);

}

Load();// 將煙花圖片信息加載進相應結構中

BeginBatchDraw();// 開始批量繪圖

while (!kbhit())

{

Sleep(10);

// 隨機選擇 4000 個像素點擦除

for (int clr = 0; clr

{

for (int j = 0; j

{

int px1 = rand() % 1200;

int py1 = rand() % 800;

if (py1

pMem[py1 * 1200 + px1] = pMem[py1 * 1200 + px1 + 1] = BLACK;// 對顯存賦值擦出像素點

}

}

Chose(t1);// 篩選煙花

Shoot();// 發射煙花

Show(pMem);// 綻放煙花

Style(st1);// 花樣發射

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

}

}

void welcome()

{

//setfillstyle(0);

setcolor(YELLOW);

for (int i = 0; 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, "寫段代碼送女友!");

Sleep(25);

}

getchar();

cleardevice();

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

outtextxy(400, 200, "原來你是我最想留住的幸運");

outtextxy(400, 250, "原來我們和愛情曾經靠得那么近");

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

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

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

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

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

getchar();

}

PS:前面的一部分弄出來了 基于代碼是真心太多,也需要圖片,插件、、、所以說,需要的可以+,后面的幾個點:1、 初始化煙花參數 /2、加載圖片/3、在一定范圍內篩選可發射的煙花,并初始化發射參數,輸出煙花彈到屏幕,播放聲音/4、掃描煙花彈并發射/5、顯示花樣/6、綻放煙花 到時候一并會發的

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容