wGame.cpp
上传用户:semy2100
上传日期:2013-01-22
资源大小:3633k
文件大小:6k
源码类别:

射击游戏

开发平台:

Visual C++

  1. /********************************************************************
  2. *                        空运爆发                                    *
  3. *                       Version 2.0                                  *
  4. * 本游戏全部代码由:                                                 *
  5. *                   冲天实验室   梁锋 编写                           *
  6. *                    邮箱:lenwine@126.com                           *
  7. *                bbs: http://free2.e-168.cn/lenwind (正在开发中...)  *
  8. **********************************************************************/
  9. #include "stdafx.h"
  10.  BOOL bActive=TRUE; //应用程序是否活跃
  11.  int speed=12; //延时速度
  12.  int movespeed=2; //移动速度
  13.  int fps; //帧频率
  14. #define MAX_LOADSTRING 100
  15. // Global Variables:
  16. HINSTANCE hInst; // current instance
  17. TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  18. TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
  19. Manager *play=NULL;
  20. /*/-----------------------Function_Begin
  21. void OnCreate(HWND hWnd);
  22. void appear(HDC hdc,LPRECT lprect);
  23. HBITMAP bm;
  24. HDC     bmdc;
  25. //-----------------------Function_End*/
  26. // Foward declarations of functions included in this code module:
  27. ATOM MyRegisterClass(HINSTANCE hInstance);
  28. BOOL InitInstance(HINSTANCE, int);
  29. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  30. int APIENTRY WinMain(HINSTANCE hInstance,
  31.                      HINSTANCE hPrevInstance,
  32.                      LPSTR     lpCmdLine,
  33.                      int       nCmdShow)
  34. {
  35.   // TODO: Place code here.
  36. MSG msg;
  37. HACCEL hAccelTable;
  38. // Initialize global strings szTitle
  39. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  40. LoadString(hInstance, IDC_WGAME, szWindowClass, MAX_LOADSTRING);
  41. MyRegisterClass(hInstance);
  42. // Perform application initialization:
  43. if (!InitInstance (hInstance, nCmdShow)) 
  44. {
  45. return FALSE;
  46. }
  47. /** if(!(play->InitDDraw()))
  48. {
  49. }**/
  50. hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WGAME);
  51. /**
  52. // Main message loop:
  53. while (GetMessage(&msg, NULL, 0, 0)) 
  54. {
  55. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
  56. {
  57. TranslateMessage(&msg);
  58. DispatchMessage(&msg);
  59. }
  60. }
  61. */
  62. while(1)
  63. {
  64. if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  65. {
  66. if(!GetMessage(&msg,NULL,0,0))
  67. break;
  68. TranslateMessage(&msg);
  69. DispatchMessage(&msg);
  70. }else if(bActive)
  71. {
  72. //计算帧频率
  73. static int frame=0, nt, ot=0;
  74. nt=GetTickCount(); 
  75. if (nt > ot+1000)
  76. {
  77. ot=nt;
  78. fps=frame;
  79. frame=0;
  80. }
  81. //画面延时
  82. static int NewCount, OldCount=0;
  83. NewCount=GetTickCount(); 
  84. if (NewCount > OldCount+speed)
  85. {
  86. frame++;
  87. OldCount=NewCount;
  88. //play->UpdateFrame();//更新画面
  89. }
  90. }
  91. //等待消息
  92. play->Update();
  93. }
  94. delete play;
  95. return msg.wParam;
  96. }
  97. //
  98. //  FUNCTION: MyRegisterClass()
  99. //
  100. //  PURPOSE: Registers the window class.
  101. //
  102. //  COMMENTS:
  103. //
  104. //    This function and its usage is only necessary if you want this code
  105. //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
  106. //    function that was added to Windows 95. It is important to call this function
  107. //    so that the application will get 'well formed' small icons associated
  108. //    with it.
  109. //
  110. ATOM MyRegisterClass(HINSTANCE hInstance)
  111. {
  112. WNDCLASSEX wclass;
  113. wclass.cbSize = sizeof(WNDCLASSEX); 
  114. wclass.style = CS_HREDRAW | CS_VREDRAW;
  115. wclass.lpfnWndProc = (WNDPROC)WndProc;
  116. wclass.cbClsExtra = 0;
  117. wclass.cbWndExtra = 0;
  118. wclass.hInstance = hInstance;
  119. wclass.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_WGAME);
  120. wclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  121. wclass.hbrBackground = (HBRUSH)(RGB(0,0,0));//COLOR_WINDOW+1
  122. wclass.lpszMenuName = (LPCSTR)IDC_WGAME;
  123. wclass.lpszClassName = szWindowClass;
  124. wclass.hIconSm = LoadIcon(wclass.hInstance, (LPCTSTR)IDI_SMALL);
  125.     
  126. return RegisterClassEx(&wclass);
  127. }
  128. //
  129. //   FUNCTION: InitInstance(HANDLE, int)
  130. //
  131. //   PURPOSE: Saves instance handle and creates main window
  132. //
  133. //   COMMENTS:
  134. //
  135. //        In this function, we save the instance handle in a global variable and
  136. //        create and display the main program window.
  137. //
  138. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  139. {
  140.    HWND hWnd;
  141.    hInst = hInstance; // Store instance handle in our global variable//szTitle
  142. //CW_USEDEFAULT  WS_OVERLAPPEDWINDOW  
  143.    hWnd = CreateWindow(szWindowClass, NULL, WS_POPUP,
  144.       NULL, NULL, NULL, NULL, NULL, NULL, hInstance, NULL);
  145.    if (!hWnd)
  146.    {
  147.       return FALSE;
  148.    }
  149.    ShowWindow(hWnd, nCmdShow);
  150.    UpdateWindow(hWnd);
  151.     play=new Manager(hWnd);
  152. return TRUE;
  153. }
  154. /*/--------------------------//
  155. void OnCreate(HWND hWnd)
  156. {
  157. HDC dc=GetDC(play->MgrFace);
  158. bmdc=CreateCompatibleDC(dc);
  159. bm=(HBITMAP)LoadImage(NULL,"bwGame.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
  160. SelectObject(bmdc,bm);
  161. }
  162. void appear(HDC hdc,LPRECT lprect)
  163. {
  164. BitBlt(hdc,0,0,600,500,bmdc,0,0,SRCCOPY);
  165. }
  166. //--------------------------/*/
  167. //
  168. //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
  169. //
  170. //  PURPOSE:  Processes messages for the main window.
  171. //
  172. //  WM_COMMAND - process the application menu
  173. //  WM_PAINT - Paint the main window
  174. //  WM_DESTROY - post a quit message and return
  175. //
  176. //
  177. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  178. {
  179. int wmId, wmEvent;
  180. PAINTSTRUCT ps;
  181. HDC hdc;
  182. switch (message) 
  183. {
  184. case WM_COMMAND:
  185. wmId    = LOWORD(wParam); 
  186. wmEvent = HIWORD(wParam); 
  187. // Parse the menu selections:
  188. switch (wmId)
  189. {
  190. case IDM_EXIT:
  191.    DestroyWindow(hWnd);
  192.    break;
  193. default:
  194.    return DefWindowProc(hWnd, message, wParam, lParam);
  195. }
  196. break;
  197. case WM_SETCURSOR:
  198. SetCursor( NULL );
  199. break;
  200. case WM_PAINT:
  201. hdc = BeginPaint(hWnd, &ps);
  202. // TODO: Add any drawing code here...
  203. // RECT rect;
  204. // GetClientRect(hWnd,&rect);
  205. // appear(hdc,&rect);
  206. EndPaint(hWnd, &ps);
  207. break;
  208. case WM_DESTROY:
  209. // play->FreeDDraw();
  210. PostQuitMessage(0);
  211. break;
  212. // case WM_CREATE:
  213. // OnCreate(hWnd);
  214. // break;
  215. case WM_KEYDOWN:
  216. play->KeyDown(wParam);
  217.             break;
  218. case WM_KEYUP:
  219. play->KeyUp(wParam);
  220. break;
  221. default:
  222. return DefWindowProc(hWnd, message, wParam, lParam);
  223.    }
  224.    return 0;
  225. }
  226. // Mesage handler for about box.