⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 worldeditor.cpp

📁 用VC++及DirectX实现的SuperMario小游戏
💻 CPP
字号:
/*
Author: Bear

This source is free to anybody.
If you have any problem with this or some advice to me, please:
    mailto: heyang22118952.student@sina.com
        or  yang45249.student@sina.com
or you can contact me through my QQ:     261570581

Welcome to discuss game programming techniques with me :)
And I like to play games!
*/
//SuperMarioDemo.cpp - Main file for "SuperMarioDemo" application
//Author: Bear

#include "SWEGame.h"

HWND hwndMain;
HINSTANCE hInstance;

SWEGame game;

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	// this is the main message handler of the system
	PAINTSTRUCT		ps;		// used in WM_PAINT
	HDC				hdc;	// handle to a device context

	// what is the message 
	switch(msg)
	{	
	case WM_CREATE: 
		{
			// do initialization stuff here

			// return success
			return(0);
		} break;

	case WM_PAINT: 
		{
			// simply validate the window 
			hdc = BeginPaint(hwnd,&ps);	 

			// end painting
			EndPaint(hwnd,&ps);

			// return success
			return(0);
		} break;

	case WM_DESTROY: 
		{

			game.CloseWindow();
			// kill the application, this sends a WM_QUIT message 
			PostQuitMessage(0);

			// return success
			return(0);
		} break;

	default:break;

	} // end switch

	// process any messages that we didn't take care of 
	return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc

int WINAPI WinMain(	HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
	WNDCLASSEX winclass; // this will hold the class we create
	HWND	   hwnd;	 // generic window handle
	MSG		   msg;		 // generic message
	// first fill in the window class stucture
	winclass.cbSize         = sizeof(WNDCLASSEX);
	winclass.style			= CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
	winclass.lpfnWndProc	= WindowProc;
	winclass.cbClsExtra		= 0;
	winclass.cbWndExtra		= 0;
	winclass.hInstance		= hinstance;
	winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	winclass.hCursor		= LoadCursor(NULL, IDC_ARROW); 
	winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
	winclass.lpszMenuName	= NULL;
	winclass.lpszClassName	= WINDOW_CLASS_NAME;
	winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
	// save hinstance in global
	hInstance = hinstance;
	// register the window class
	if (!RegisterClassEx(&winclass))
		return(0);
	//adjust window
	RECT wndRect = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT+SLICE_HEIGHT};
	AdjustWindowRectEx(&wndRect, (WINDOWED_APP ? WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE : WS_POPUP | WS_VISIBLE), FALSE, NULL);	//test window mode
	// create the window
	int wndX = (GetSystemMetrics(SM_CXSCREEN) - wndRect.right + wndRect.left) / 2;
	int wndY = (GetSystemMetrics(SM_CYSCREEN) - wndRect.bottom + wndRect.top) / 2;
	if (!(hwnd = CreateWindowEx(NULL, WINDOW_CLASS_NAME, "DirectX Game Application Framework", 
		(WINDOWED_APP ? WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE : WS_POPUP | WS_VISIBLE), wndX, wndY,
		wndRect.right - wndRect.left, wndRect.bottom - wndRect.top, NULL, NULL,	hinstance, NULL)))
		return(0);
	// save main window handle
	hwndMain = hwnd;
	//ShowCursor(FALSE);
	// initialize game here
	if(!game.Initialize(hinstance, hwnd, WINDOWED_APP ? true : false, SCREEN_WIDTH, SCREEN_HEIGHT+SLICE_HEIGHT, SCREEN_BPP)) {
		game.ShutDown();
		return 0;
	}
	// enter main event loop
	while(TRUE)
	{
		// test if there is a message in queue, if so get it
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{ 
			// test if this is a quit
			if (msg.message == WM_QUIT)
				break;
			// translate any accelerator keys
			TranslateMessage(&msg);
			// send the message to the window proc
			DispatchMessage(&msg);
		} // end if
		// main game processing goes here
		if(!game.Run()) {
			break;
		}
	} // end while
	// closedown game here
	game.ShutDown();
	//ShowCursor(TRUE);
	// return to Windows like this
	return (int)(msg.wParam);
} // end WinMain

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -