您的位置:首页 > 其它

魔塔 游戏开发 3

2013-01-16 19:07 113 查看
----------------------window.cpp--------------------------------------

#include "Game.h"

//=======================Values=============================

int nWindowltX=(GetSystemMetrics(SM_CXSCREEN)-1000)/2;      //left top x position

int nWindowltY=(GetSystemMetrics(SM_CYSCREEN)-700)/2-30;    //left top y position

#define WINDOWW 1000                                        //window width

#define WINDOWH 700+34                                      //window height

HWND hWnd;

HDC hdc;

//=====================Functions======================================

bool MyInitWindow(HINSTANCE hInstance,int nShowCmd);

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

//=====================WinMain=======================================

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

{
MSG msg;
if(!MyInitWindow(hInstance,nShowCmd))
{
return 0;
}
if(!Game_Init(hdc))
{
return 0;
}

while(!bGameOver)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

Game_Run(hdc);
}

Game_ShutDown();

return 1;

}

bool MyInitWindow(HINSTANCE hInstance,int nShowCmd)

{
WNDCLASSEX wndex;
wndex.cbClsExtra=0;
wndex.cbSize=sizeof(WNDCLASSEX);
wndex.cbWndExtra=0;
wndex.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndex.hCursor=LoadCursor(NULL,IDC_ARROW);
wndex.hIcon=NULL;
wndex.hIconSm=NULL;
wndex.hInstance=hInstance;
wndex.lpfnWndProc=MsgProc;
wndex.lpszClassName=L"Window";
wndex.lpszMenuName=NULL;
wndex.style=CS_HREDRAW||CS_VREDRAW;
if(!RegisterClassEx(&wndex))
{
MessageBox(NULL,L"register error!",NULL,MB_OK);
return false;
}

hWnd=CreateWindow(L"Window",L"MyWindow",WS_OVERLAPPEDWINDOW,
nWindowltX,nWindowltY,WINDOWW,WINDOWH,
NULL,NULL,hInstance,NULL);
if(!hWnd)
{
MessageBox(NULL,L"CrateWindow error!",NULL,MB_OK);
return false;
}
ShowWindow(hWnd,nShowCmd);
UpdateWindow(hWnd);

hdc=GetDC(hWnd);
return true;

}

LRESULT CALLBACK MsgProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)

{
switch(message)
{
case WM_DESTROY:
bGameOver=true;
PostQuitMessage(0);
break;
case WM_MOUSEMOVE:
if(bIsStartScreen)
{
WORD x=LOWORD(lParam);
WORD y=HIWORD(lParam);

if((x>10)&&(x<120)&&y>600&&y<650)//在按钮上
{
nBtnStart_y=60;
bIsBtnS=true;
}
else//不在按钮上
{
nBtnStart_y=0;
bIsBtnS=false;
bBtnSHave=false;
}

if(x>150&&x<250&&y>600&&y<650)
{
nBtnEnd_y=60;
bIsBtnE=true;
}
else
{
nBtnEnd_y=0;
bIsBtnE=false;
bBtnEHave=false;
}
}
break;
case WM_LBUTTONDOWN:
if(bIsStartScreen)
{
WORD x=LOWORD(lParam);
WORD y=HIWORD(lParam);

if((x>10)&&(x<120)&&y>600&&y<650)//在按钮上
{
bStartToMapScroll=true;

}
if(x>150&&x<250&&y>600&&y<650)
{
bGameOver=true;
PostQuitMessage(0);
}
}
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Directx 小游戏 魔塔