?? gtgame.cpp
字號:
// gtGame.cpp: implementation of the gtGame class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "gtGame.h"
#include "CDInput.h"
#include "resource.h"
#include "log.h"
#include <stdio.h>
#define ENABLE_TRACE
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//BEGIN_MAP_MESSAGE
const WMessageFunc GtGame::messageEntries[]={
{0,0},
MAP_MESSAGE(WM_LBUTTONDOWN,OnLButtonDown)
MAP_MESSAGE(WM_DESTROY,OnDestroy)
MAP_MESSAGE(WM_KEYDOWN,OnKeyDown)
END_MAP_MESSAGE()
CDIKeyBoard theKeyBoard;
CDIMouse theMouse;
GtGame::GtGame(HINSTANCE hInstance,int nCmdShow) : hInstance(hInstance) , nCmdShow(nCmdShow)
{
}
GtGame::~GtGame()
{
}
ATOM GtGame::MyRegisterClass()
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = 0;
wcex.lpfnWndProc = (WNDPROC)GtGame::_ProcFn;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "raomiao";
wcex.hIconSm =LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
/*
函數(shù)名稱: Create
函數(shù)全名: gtGame::MainLoop
函數(shù)權(quán)限: public
返回類型: void
函數(shù)版本: 1.0
函數(shù)功能:
游戲主消息循環(huán)
*/
void GtGame::Create()
{
this->MyRegisterClass();
this->GameHwnd = CreateWindow("raomiao", "Chess", WS_OVERLAPPEDWINDOW,0,0,
GetSystemMetrics( SM_CXSCREEN ),
GetSystemMetrics( SM_CYSCREEN ),
NULL,NULL,hInstance,NULL);
if (!this->GameHwnd)
{
MessageBox(NULL,"錯誤","初始化失敗",MB_OK);
return ;
}
ShowWindow(this->GameHwnd, nCmdShow);
UpdateWindow(this->GameHwnd);
SetWindowLong(GameHwnd, GWL_USERDATA, (LONG) this );
// surface.Init();
InitEasyDraw(this->GameHwnd,false,800,600);
// surface.CreateImageSurface("move.bmp",1024,768,DDBLTFAST_NOCOLORKEY);
// surface.SetSurfaceColorKey(0xf81f);
// surface1.CreateImageSurface("iron_barrier_02.bmp",117,195,DDBLTFAST_NOCOLORKEY);
// surface1.SetSurfaceColorKey(0xf81f);
map.Init("my.bmp",20,20);
// build.Init("iron_barrier_02.bmp",0,0);
hero.Init("my2.bmp",200,200);
// CDInput::InitDInput(this->hInstance);
theKeyBoard.Init(this->GameHwnd,this->hInstance);
theMouse.Init(this->GameHwnd,this->hInstance);
timer.UpdateFps();
font=CreateFont(15,8,0,0,FW_EXTRALIGHT
,0,0,0,DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH,"楷體_GB2312");
// Easydraw=new EasyDraw();
// Easydraw->InitDDraw(GameHwnd,800,600);
}
LRESULT CALLBACK GtGame::_ProcFn ( HWND hwnd, UINT uMsg,WPARAM wParam, LPARAM lParam )
{
GtGame *wnd=(GtGame*)GetWindowLong(hwnd,GWL_USERDATA);
if (wnd) {
const WMessageFunc *mf=wnd->GetMessageEntries();
do {
int i;
for (i=1;mf[i].func;i++) {
if (mf[i].id==uMsg) {
if ((wnd->*(mf[i].func))(wParam,lParam)==-1)
return 0;
else break;
}
}
mf=(const WMessageFunc*)(mf[0].id);
} while (mf!=0);
}
return DefWindowProc(hwnd,uMsg, wParam, lParam);
}
/*
函數(shù)名稱: MainLoop
函數(shù)全名: gtGame::MainLoop
函數(shù)權(quán)限: public
返回類型: int
函數(shù)版本: 1.0
函數(shù)功能:
游戲主消息循環(huán)
調(diào)用:
[API]PeekMessage
[API]TranslateMessage
[API]DispatchMessage
[API]WaitMessage
*/
int GtGame::MainLoop()
{
MSG msg;
bool bIsQuit = false;
while ( !bIsQuit )
{
if(::PeekMessage(&msg, NULL, 0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
bIsQuit = true;
}
::TranslateMessage( &msg );
::DispatchMessage( &msg );
}
else
{
RECT rect={0,0,1024,768};
RECT rect1={0,0,153,117};
theMouse.UpdateMouse(this->GameHwnd);
map.MoveMap();
map.ShowMap();
if(theMouse.IsLPress())
{
MessageBox(this->GameHwnd,"dsf","",MB_OK);
}
hero.ShowBuilding(map.view);
timer.UpdateFps();
HDC hdc;
::SelectObject(hdc,font);
// char text="雕花籠·絕代雙驕前傳·主題曲";
if (GetEasyDrawPointer()->GetBackSurface()->GetDC(&hdc) == DD_OK)
{
::SelectObject(hdc,font);
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc, RGB(255, 255, 255));
char str[128];
sprintf(str,"FPS:%d/s",timer.GetFps());
TextOut(hdc,10,10, str,strlen(str));
GetEasyDrawPointer()->GetBackSurface()->ReleaseDC(hdc);
}
::ReleaseDC(this->GameHwnd,hdc);
GetEasyDrawPointer()->Filp();
Sleep(0);
// Sleep(10);
// Sleep(50);
}
}
return msg.wParam;
}
int GtGame::OnLButtonDown(DWORD w,DWORD l)
{
RECT rect={0,0,200,200};
surface.CopySurfaceToBmp("test.bmp",&rect);
return 0;
}
int GtGame::OnDestroy(DWORD w,DWORD l)
{
PostQuitMessage(0);
return 0;
}
int GtGame::OnKeyDown(DWORD w,DWORD l)
{
if(::GetKeyState(VK_ESCAPE) & 0x80)
{
::SendMessage(this->GameHwnd, WM_CLOSE, 0, 0 );
}
return 0;
}
/*
End-Of-File "gtGame.cpp"
*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -