C++源代码游戏编程--WinMain()函数集.doc_第1页
C++源代码游戏编程--WinMain()函数集.doc_第2页
C++源代码游戏编程--WinMain()函数集.doc_第3页
C++源代码游戏编程--WinMain()函数集.doc_第4页
C++源代码游戏编程--WinMain()函数集.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 PASCALWinMain(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 PASCALWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) MSG msg; if (InitApp(hInstance, nCmdShow) != DD_OK) return FALSE; Map0.Width=width; Map0.Hight=height; Map0.Data=(char *)malloc( Map0.Width * Map0.Hight ); Map0.Pro=(char *)malloc( Map0.Width * Map0.Hight ); /将地图全部置为可到达 int i,j; reachable=1; for (j=0;jMap0.Hight;j+) for (i=0;iMap0.Width;i+) *(Map0.Data+i*Map0.Hight+j)=reachable; for (j=0;jMap0.Hight;j+) for (i=0;iGetDirectDraw()-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;

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论