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

📄 wndmsg.cpp

📁 俄罗斯方块3D 程序+源码俄罗斯方块3D(程序+源码
💻 CPP
字号:
#include <windows.h>
#include <commctrl.h>
#include "WndMsg.h"
#include "MsgHelp.h"
#include "BaseKey.h"

#include "CAppWnd.h"
#include "CTimer.h"

#include "CD3DApp.h"
#include "CShakingCamera.h"

#include "CMenu.h"
#include "CStatusBar.h"

#include "CBlockFollowing.h"
#include "CGameManager.h"
#include "CGameState.h"

extern bool					g_IsActive;
extern CAppWnd				theAppWnd;						//窗口
extern CTimer				theTimer;

extern CD3DApp				theD3DApp;						//D3D设备
extern CShakingCamera		theCamera;

extern CMenu				theMenu;						//菜单
extern CStatusBar			theStatusBar;					//状态栏								

extern CGameManager			theGameManager;					//游戏逻辑管理
extern CBlockFollowing		theBlockFollowing;
extern CGameState			theGameState;

///////////////////////////////////////////////////////////
//初始化图形层:
///////////////////////////////////////////////////////////
bool InitLogic()
{
	return theGameManager.Init();
}


///////////////////////////////////////////////////////////
//初始化图形层:
///////////////////////////////////////////////////////////
void FreeLogic()
{
	theGameManager.Free();
}

///////////////////////////////////////////////////////////
//初始化逻辑层:
///////////////////////////////////////////////////////////
bool InitGraphics( HWND hwnd )
{
	if ( theD3DApp.InitD3D( true, hwnd ) )
	{
		return theD3DApp.InitApp();
	}
	return false;
}

///////////////////////////////////////////////////////////
//初始化用户交互层:
///////////////////////////////////////////////////////////
bool InitGUI( HWND hwnd, HINSTANCE hInstance )
{
	InitCommonControls();
	//theToolBar1.Init( hwnd, hInstance );
	theStatusBar.Init( hwnd, hInstance );
	return true;
}

///////////////////////////////////////////////////////////
//程序结束工作
///////////////////////////////////////////////////////////
void OnQuit()
{
	FreeLogic();

	theD3DApp.FreeApp();
	theD3DApp.FreeD3D();

	theMenu.Free();
	theStatusBar.Free();

	PostQuitMessage( NULL );
}

///////////////////////////////////////////////////////////
//响应按键函数
///////////////////////////////////////////////////////////
void OnKeyDown( WPARAM wP )
{
	switch ( wP )
	{
	/*case VK_A:
		theCamera.strafe( 0.1f );
		break;
	case VK_D:
		theCamera.strafe( -0.1f );
		break;
	case VK_W:
		theCamera.fly( -0.1f );
		break;
	case VK_S:
		theCamera.fly( 0.1f );
		break;
	case VK_Q:
		theCamera.RotationY( 0.1f );
		break;
	case VK_E:
		theCamera.RotationY( -0.1f );
		break;
	case VK_F1:
		theCamera.LookAtX( -6.0f );
		break;
	case VK_F2:
		theCamera.LookAtY( -6.0f );
		break;
	case VK_F3:
		theCamera.LookAtZ( -6.0f );
		break;
	case VK_F4:
		theCamera.Slope45();
		break;*/
	case VK_LEFT:
		theBlockFollowing.Move( true );
		break;
	case VK_RIGHT:
		theBlockFollowing.Move( false );
		break;
	case VK_UP:
		theBlockFollowing.Rotate();
		break;
	case VK_DOWN:
		theBlockFollowing.Drop();
		break;
	case VK_RETURN:
		theGameState.PauseGame();	
		break;
	}
}

///////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////
void OnGUIItem( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{	
	//if ( !theToolBar1.HandleMsg( hwnd, msg, wParam, lParam ) )
		theMenu.HandleMsg( hwnd, msg, wParam, lParam );
}


///////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////
void OnSize( LPARAM lParam )
{
	RECT rc, rcSB;
	long WndHeight, SBHeight, x, y;
	
	long width;
	HWND hSB = theStatusBar.GetHWnd();
	HWND hWnd = theAppWnd.GetHWnd();
	//HWND hTB = theToolBar1.GetHWnd();							//工具条(如果没有工具条,设0)
	//RECT rcTB;
	long TBHeight = 0;

	GetWindowRect( hSB, &rcSB );
	GetClientRect( hWnd, &rc );
	//GetWindowRect( hTB, &rcTB );
	
	SBHeight = rcSB.bottom - rcSB.top;
	//TBHeight = rcTB.bottom - rcTB.top;
	WndHeight = rc.bottom - rc.top - SBHeight - TBHeight;
	width = rc.right - rc.left;

	
	x = LOWORD( lParam );
	y = HIWORD( lParam );

	SetWindowPos( theAppWnd.GetHDisplayWnd(), HWND_TOP, 
				0, TBHeight, 
				width, 
				WndHeight,
				SWP_SHOWWINDOW );									//调整子窗口
	//SendMessage( hTB, TB_AUTOSIZE, 0, 0 );						//调整工具条
	MoveWindow( hSB, 0, y - SBHeight, x, y, TRUE );					//调整状态栏
	theStatusBar.SetParts();
}


///////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////
void OnLoop()
{
	theGameManager.OnGameRun();
	theCamera.Shake();
	theD3DApp.Render();
	theTimer.UpdateFps();
}


void ActiveWnd()
{
	g_IsActive = true;
	SetWindowText( theAppWnd.GetHWnd(), "RussiaGame3D-Active" );
}

void InactiveWnd()
{
	g_IsActive = false;
	SetWindowText( theAppWnd.GetHWnd(), "RussiaGame3D-Inactive" );
}

⌨️ 快捷键说明

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