激情六月丁香婷婷|亚洲色图AV二区|丝袜AV日韩AV|久草视频在线分类|伊人九九精品视频|国产精品一级电影|久草视频在线99|在线看的av网址|伊人99精品无码|午夜无码视频在线

高校合作1:010-59833514 ?咨詢電話:400-810-1418 服務(wù)與監(jiān)督電話:400-810-1418轉(zhuǎn)接2

c++框架游戲開發(fā)(想學(xué)習(xí)C/C++來寫游戲程序么?大神告訴你游戲框架怎么寫)

發(fā)布時間:2023-11-27 04:22:28 瀏覽量:111次

?想學(xué)習(xí)C/C++來寫游戲程序么?大神告訴你游戲框架怎么寫

c++框架游戲開發(fā)(想學(xué)習(xí)C/C++來寫游戲程序么?大神告訴你游戲框架怎么寫)

對這方面感興趣或者想學(xué)習(xí)C/C++可以加群:558502932,有問題可以在群內(nèi)大家一起交流學(xué)習(xí)。

對于正在學(xué)習(xí)C/C++的同學(xué)或者朋友來說,如何用C/C++寫程序都有些模糊的概念,畢竟如果只是學(xué)習(xí)C/C++的理論知識,很多人甚至都不知道C/C++學(xué)了能干嘛。

有很多人都想去往游戲方面發(fā)展,畢竟能寫出一個游戲供大家學(xué)習(xí)是一件特別自豪的事情。但是要寫出一個游戲,不是那么容易的事情,今天我就來分享一下,我們講師寫過的一個游戲框架,希望能對你們有所幫助。

對這方面感興趣或者想學(xué)習(xí)C/C++可以加群:558502932

代碼如下:

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//

// WindowsFrame.cpp: This is a Windows-Game Forms

// Author: MOYG

// Date: Dec-19-2015

// Version 1.0

//

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// INCLUDEs ////////////////////////////////////////////////////////////////////////////////////////////////////

#include "windows.h"

#include "time.h“

// DEFINES ////////////////////////////////////////////////////////////////////////////////////////////////////

#define WINDOW_WIDTH 800 //Window width of a macro definition

#define WINDOW_HEIGHT 600 //Window height of a macro definition

#define WINDOW_TITLE L"【潭州教育】程序核心框架" //The window title of marco definition

// GLOBALS /////////////////////////////////////////////////////////////////////////////////////////////////////

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam ); //The process window function

// WINMAIN /////////////////////////////////////////////////////////////////////////////////////////////////////

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)

{

//【1】 窗口創(chuàng)建四部曲之一:開始設(shè)計一個完整的窗口類

//【First】 One of the windows to create tetralogy:Start to design a whole window calss

WNDCLASSEX wndClass = { 0 }; //With WNDCALSSEX definition of a window class

wndClass.cbSize = sizeof(WNDCLASSEX); //Number of bytes to set up the structure size

wndClass.style = CS_HREDRAW | CS_VREDRAW; //Set the window style

wndClass.lpfnWndProc = WndProc; //Set the pointer to the window procedure function

wndClass.cbClsExtra = 0; //Additional memory window class

wndClass.cbWndExtra = 0; //Additional memory window

wndClass.hInstance = hInstance; //Specified contains the window handle to an instance of the process of program

//Local load custom ico

wndClass.hIcon = (HICON)::LoadImage(NULL, L"icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);

wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); //Specifies the window handle of the cursor

wndClass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); //The handle of Brush

wndClass.lpszMenuName = NULL; //Specify the menu resource

wndClass.lpszClassName = L"ForTheDreamOfGameDevelop";

//【2】窗口創(chuàng)建四部曲之二:注冊窗口類

//【Second】 Second of the window to create tetralogy: RegisterClass

if (!RegisterClassEx(&wndClass))

return -1;

//【3】窗口創(chuàng)建四部曲之三:正式創(chuàng)建窗口

//【Third】 Third of the window to create tetralogy:Formal creation window

c++框架游戲開發(fā)(想學(xué)習(xí)C/C++來寫游戲程序么?大神告訴你游戲框架怎么寫)

HWND hwnd = CreateWindow(L"ForTheDreamOfGameDevelop",

WINDOW_TITLE, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,

WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);

//【4】窗口創(chuàng)建四部曲之四:窗口移動、顯示與更新

//【Four】 Fourth of the window to create tetralogy:Windows moblie,display and update

MoveWindow(hwnd, 250, 80, WINDOW_WIDTH, WINDOW_HEIGHT, true); //In the left corner of the window(250,70);

ShowWindow(hwnd,nShowCmd); //Display window

UpdateWindow(hwnd); //Update window

//【5】消息循環(huán)過程

//windows information rotation

MSG msg = { 0 }; //init msg

while (msg.message != WM_QUIT)

{

//查看應(yīng)用程序消息隊(duì)列,有消息時將隊(duì)列中消息派發(fā)出去

if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))

{

TranslateMessage(&msg); //將虛擬消息轉(zhuǎn)換為字符信息

DispatchMessage(&msg); //分發(fā)一個消息給窗口程序

}

}

//【6】窗口類的注銷

//【Sixth】 logout window class

UnregisterClass(L"ForDearmOfGameClassDevelop", wndClass.hInstance);

return 0;

}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

switch (message)

{

case WM_PAINT: //重繪消息

ValidateRect(hwnd, NULL); //更新客戶的顯示

break;

case WM_KEYDOWN: //若是鍵盤按下任意鍵消息

if (wParam == VK_ESCAPE) //如果按下的是ESC鍵

DestroyWindow(hwnd); //銷毀窗口,并發(fā)送一條WM_DESTORY消息

break;

case WM_DESTROY: //若是窗口銷毀消息

PostQuitMessage(0); //像系統(tǒng)表示有個線程有終止請求,用來響應(yīng)WM_DESTROY消息

break;

default:

return DefWindowProc(hwnd, message, wParam, lParam); //調(diào)用默認(rèn)的窗口過程

}

return 0;

}

以上,就是游戲框架設(shè)計的源程序,希望對你們有所幫助,當(dāng)然,你們?nèi)绻信d趣可以運(yùn)行試試,如果有什么問題,可以加群:558502932,把問題發(fā)到群里,或者找群內(nèi)管理問一下,會幫你解答的。

希望你們學(xué)習(xí)C/C++都能學(xué)有所成。

c++框架游戲開發(fā)(想學(xué)習(xí)C/C++來寫游戲程序么?大神告訴你游戲框架怎么寫)

熱門課程推薦

熱門資訊

請綁定手機(jī)號

x

同學(xué)您好!

您已成功報名0元試學(xué)活動,老師會在第一時間與您取得聯(lián)系,請保持電話暢通!
確定