C++源代码游戏编程--WinMain()函数集

C++源代码游戏编程--WinMain()函数集
 
 

C++源代码游戏编程--WinMain()函数交流

//******************************************************************
//函数:WinMain()
//功能:应用程序入口
//******************************************************************
int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    hInst=hInstance;

    //初始化主窗口
    if (!InitWindow( hInstance, nCmdShow))
    return FALSE;

    //初始化DirectDraw环境
    if (!InitDDraw())
    {
        MessageBox(hWndMain, "初始化DirectDraw过程中出错!", "Error", MB_OK);
        FreeObjects();
        DestroyWindow(hWndMain);
        return FALSE;
    }

    //进入消息循环
    while(1)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
        {
            if(!GetMessage(&msg, NULL, 0, 0 )) return msg.wParam;
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else if(bActive)
        {
            UpdateFrame();
        }
        else WaitMessage();
        }

    return msg.wParam;
}

///


//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Initialization, message loop
//-----------------------------------------------------------------------------
int PASCAL
WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
    MSG msg;

    if (InitApp(hInstance, nCmdShow) != DD_OK)
        return FALSE;

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

/
// 主循环
/
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;


    if(!InitApp(hInst, nCmdShow)) return FALSE;

    while(1)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
        {
            if(!GetMessage(&msg, NULL, 0, 0 )) return msg.wParam;
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else if(bActive)
        {
            Update();

            // 翻转上一层缓冲区内容到屏幕。
            Screen->Flip();
        }
        else WaitMessage();
    }
}

///
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
    // any windows programmer should be familiar with this

    MSG msg;

    lpCmdLine = lpCmdLine;
    hPrevInstance = hPrevInstance;
    if(!doInit(hInstance, nCmdShow))
    {
        return FALSE;
    }

    while (1)
    {
        if(PeekMessage(&msg, NULL, 0,0,PM_NOREMOVE))
        {
            if(!GetMessage(&msg, NULL,0,0))
                return msg.wParam;
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else if(bActive)
        {
            fire(480, 0, 600, 50);
            // draw fire on bottom row and then flip
            while(1)
            {
                ddrval = lpDDSPrimary->Flip(NULL, DDFLIP_WAIT);
                if(ddrval == DD_OK)
                {
                    break;
                }
                if(ddrval == DDERR_SURFACELOST)
                {
                    if(ddrval != DD_OK)
                    {
                        break;
                    }
                }
                if(ddrval != DDERR_WASSTILLDRAWING)
                {
                    break;
                }
            }
        } // if bActive
        else
        {
            //make sure we go to sleep if have nothiing to do
            WaitMessage();
        }
    }

} // win main


//

//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: 入口,初始化,进行消息循环
//-----------------------------------------------------------------------------
int PASCAL
WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
    MSG msg;

    if (InitApp(hInstance, nCmdShow) != DD_OK)
        return FALSE;

    Map[0].Width=width;
    Map[0].Hight=height;
    Map[0].Data=(char *)malloc( Map[0].Width * Map[0].Hight );
    Map[0].Pro=(char *)malloc( Map[0].Width * Map[0].Hight );

    //将地图全部置为可到达
    int i,j;
    reachable=1;
    for (j=0;j<Map[0].Hight;j++)
        for (i=0;i<Map[0].Width;i++)
        {
            *(Map[0].Data+i*Map[0].Hight+j)=reachable;
        }

    for (j=0;j<Map[0].Hight;j++)
        for (i=0;i<Map[0].Width;i++)
        {
            *(Map[0].Pro+i*Map[0].Hight+j)=select_pro;
        }

    //消息循环
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}

//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything and calls
// UpdateFrame() when idle from the message pump.
//-----------------------------------------------------------------------------
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
    MSG msg;
    HWND hWnd;

    ZeroMemory( &g_Sprite, sizeof(SPRITE_STRUCT) * NUM_SPRITES );
    srand( GetTickCount() );

    if( FAILED( WinInit( hInst, nCmdShow, &hWnd ) ) )
        return FALSE;

    // Make a timer go off to re-init the table of random values every once in a while
    SetTimer( hWnd, 0, 1500, NULL );

    if( FAILED( InitDirectDraw( hWnd ) ) )
    {
        if( g_pDisplay )
            g_pDisplay->GetDirectDraw()->SetCooperativeLevel( NULL, DDSCL_NORMAL );

        MessageBox( hWnd, TEXT("DirectDraw init failed. ")
        TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
        MB_ICONERROR | MB_OK );
        return FALSE;
    }

    g_dwLastTick = timeGetTime();

    while( TRUE )
    {
        // Look for messages, if none are found then
        // update the state and display it
        if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
        {
            if( 0 == GetMessage(&msg, NULL, 0, 0 ) )
            {
                // WM_QUIT was posted, so exit
                return (int)msg.wParam;
            }

            // Translate and dispatch the message
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        else
        {
            if( g_bActive )
            {
                // Move the sprites, blt them to the back buffer, then
                // flip or blt the back buffer to the primary buffer
                if( FAILED( ProcessNextFrame() ) )
                {
                    SAFE_DELETE( g_pDisplay );

                    MessageBox( hWnd, TEXT("Displaying the next frame failed. ")
                    TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
                    MB_ICONERROR | MB_OK );
                    return FALSE;
                }
            }
            else
            {
                // Make sure we go to sleep if we have nothing else to do
                WaitMessage();

                // Ignore time spent inactive
                g_dwLastTick = timeGetTime();
            }
        }
    }
}

本人e-mail: fuzipin@sina,com
希望通过交流进一步提高我们的游戏开发水平,OK
 
 
 

 

转载于:https://www.cnblogs.com/3vgame/archive/2006/04/10/371778.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值