wGame.cpp
资源名称:LwGame2.0.rar [点击查看]
上传用户:semy2100
上传日期:2013-01-22
资源大小:3633k
文件大小:6k
源码类别:
射击游戏
开发平台:
Visual C++
- /********************************************************************
- * 空运爆发 *
- * Version 2.0 *
- * 本游戏全部代码由: *
- * 冲天实验室 梁锋 编写 *
- * 邮箱:lenwine@126.com *
- * bbs: http://free2.e-168.cn/lenwind (正在开发中...) *
- **********************************************************************/
- #include "stdafx.h"
- BOOL bActive=TRUE; //应用程序是否活跃
- int speed=12; //延时速度
- int movespeed=2; //移动速度
- int fps; //帧频率
- #define MAX_LOADSTRING 100
- // Global Variables:
- HINSTANCE hInst; // current instance
- TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
- TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
- Manager *play=NULL;
- /*/-----------------------Function_Begin
- void OnCreate(HWND hWnd);
- void appear(HDC hdc,LPRECT lprect);
- HBITMAP bm;
- HDC bmdc;
- //-----------------------Function_End*/
- // Foward declarations of functions included in this code module:
- ATOM MyRegisterClass(HINSTANCE hInstance);
- BOOL InitInstance(HINSTANCE, int);
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- int APIENTRY WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
- {
- // TODO: Place code here.
- MSG msg;
- HACCEL hAccelTable;
- // Initialize global strings szTitle
- LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
- LoadString(hInstance, IDC_WGAME, szWindowClass, MAX_LOADSTRING);
- MyRegisterClass(hInstance);
- // Perform application initialization:
- if (!InitInstance (hInstance, nCmdShow))
- {
- return FALSE;
- }
- /** if(!(play->InitDDraw()))
- {
- }**/
- hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WGAME);
- /**
- // Main message loop:
- while (GetMessage(&msg, NULL, 0, 0))
- {
- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- */
- while(1)
- {
- if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
- {
- if(!GetMessage(&msg,NULL,0,0))
- break;
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }else if(bActive)
- {
- //计算帧频率
- static int frame=0, nt, ot=0;
- nt=GetTickCount();
- if (nt > ot+1000)
- {
- ot=nt;
- fps=frame;
- frame=0;
- }
- //画面延时
- static int NewCount, OldCount=0;
- NewCount=GetTickCount();
- if (NewCount > OldCount+speed)
- {
- frame++;
- OldCount=NewCount;
- //play->UpdateFrame();//更新画面
- }
- }
- //等待消息
- play->Update();
- }
- delete play;
- return msg.wParam;
- }
- //
- // FUNCTION: MyRegisterClass()
- //
- // PURPOSE: Registers the window class.
- //
- // COMMENTS:
- //
- // This function and its usage is only necessary if you want this code
- // to be compatible with Win32 systems prior to the 'RegisterClassEx'
- // function that was added to Windows 95. It is important to call this function
- // so that the application will get 'well formed' small icons associated
- // with it.
- //
- ATOM MyRegisterClass(HINSTANCE hInstance)
- {
- WNDCLASSEX wclass;
- wclass.cbSize = sizeof(WNDCLASSEX);
- wclass.style = CS_HREDRAW | CS_VREDRAW;
- wclass.lpfnWndProc = (WNDPROC)WndProc;
- wclass.cbClsExtra = 0;
- wclass.cbWndExtra = 0;
- wclass.hInstance = hInstance;
- wclass.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_WGAME);
- wclass.hCursor = LoadCursor(NULL, IDC_ARROW);
- wclass.hbrBackground = (HBRUSH)(RGB(0,0,0));//COLOR_WINDOW+1
- wclass.lpszMenuName = (LPCSTR)IDC_WGAME;
- wclass.lpszClassName = szWindowClass;
- wclass.hIconSm = LoadIcon(wclass.hInstance, (LPCTSTR)IDI_SMALL);
- return RegisterClassEx(&wclass);
- }
- //
- // FUNCTION: InitInstance(HANDLE, int)
- //
- // PURPOSE: Saves instance handle and creates main window
- //
- // COMMENTS:
- //
- // In this function, we save the instance handle in a global variable and
- // create and display the main program window.
- //
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- HWND hWnd;
- hInst = hInstance; // Store instance handle in our global variable//szTitle
- //CW_USEDEFAULT WS_OVERLAPPEDWINDOW
- hWnd = CreateWindow(szWindowClass, NULL, WS_POPUP,
- NULL, NULL, NULL, NULL, NULL, NULL, hInstance, NULL);
- if (!hWnd)
- {
- return FALSE;
- }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- play=new Manager(hWnd);
- return TRUE;
- }
- /*/--------------------------//
- void OnCreate(HWND hWnd)
- {
- HDC dc=GetDC(play->MgrFace);
- bmdc=CreateCompatibleDC(dc);
- bm=(HBITMAP)LoadImage(NULL,"bwGame.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
- SelectObject(bmdc,bm);
- }
- void appear(HDC hdc,LPRECT lprect)
- {
- BitBlt(hdc,0,0,600,500,bmdc,0,0,SRCCOPY);
- }
- //--------------------------/*/
- //
- // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
- //
- // PURPOSE: Processes messages for the main window.
- //
- // WM_COMMAND - process the application menu
- // WM_PAINT - Paint the main window
- // WM_DESTROY - post a quit message and return
- //
- //
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- int wmId, wmEvent;
- PAINTSTRUCT ps;
- HDC hdc;
- switch (message)
- {
- case WM_COMMAND:
- wmId = LOWORD(wParam);
- wmEvent = HIWORD(wParam);
- // Parse the menu selections:
- switch (wmId)
- {
- case IDM_EXIT:
- DestroyWindow(hWnd);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- break;
- case WM_SETCURSOR:
- SetCursor( NULL );
- break;
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- // TODO: Add any drawing code here...
- // RECT rect;
- // GetClientRect(hWnd,&rect);
- // appear(hdc,&rect);
- EndPaint(hWnd, &ps);
- break;
- case WM_DESTROY:
- // play->FreeDDraw();
- PostQuitMessage(0);
- break;
- // case WM_CREATE:
- // OnCreate(hWnd);
- // break;
- case WM_KEYDOWN:
- play->KeyDown(wParam);
- break;
- case WM_KEYUP:
- play->KeyUp(wParam);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- // Mesage handler for about box.