游戏连载-2


////////////////////////////////////////////////////////////////MyWindow.cpp////////////////////////////////////////////////////////////////
#include "Game.h"




LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
        case WM_DESTROY:
            gameover = true;
            PostQuitMessage(0);
            return 0;
case WM_MOUSEMOVE:
{
pos_X=LOWORD(lParam);
pos_Y=HIWORD(lParam);
if(!bStartGame)
{
//如果鼠标在开始按钮上
if(pos_X>xBtnStart&&pos_X<xBtnStart+300&&pos_Y>=yBtnStart-20&&pos_Y<yBtnStart+40)
{
mouseOnStartBtn=true;
}else
{
mouseOnStartBtn=false;
}
//如果鼠标在结束按钮上
if(pos_X>xBtnEnd&&pos_X<xBtnEnd+300&&pos_Y>yBtnEnd-20&&pos_Y<yBtnEnd+40)
{
mouseOnEndBtn=true;
}else
{
mouseOnEndBtn=false;
}
}




}
break;
case WM_LBUTTONDOWN:
{
//如果鼠标在开始按钮上
if(mouseOnStartBtn)
{
bStartGame=true;
}
//如果鼠标在结束按钮上
if(mouseOnEndBtn)
{
gameover=true;
}
}
break;


    }
    return DefWindowProc( hWnd, msg, wParam, lParam );
}




int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    //initialize window settings
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX); 
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)WinProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = NULL;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = APPTITLE;
    wc.hIconSm       = NULL;
    RegisterClassEx(&wc);


    //create a new window
    HWND window = CreateWindow( APPTITLE, APPTITLE,
       WS_OVERLAPPEDWINDOW, Origin_X, Origin_Y,
       SCREENW, SCREENH, NULL, NULL, hInstance, NULL);
    if (window == 0) return 0;


    //display the window
    ShowWindow(window, nCmdShow);
    UpdateWindow(window);

//initialize the game
    if (!Game_Init(window)) return 0;


    // main message loop
MSG message;
while (!gameover)
    {
        if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) 
   {
   TranslateMessage(&message);
   DispatchMessage(&message);
   }


        //process game loop 
        Game_Run(window);
    }


    //shutdown
    Game_End();
return message.wParam;
}

你可能感兴趣的:(游戏连载-2)