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

📄 gameapp.cpp

📁 旋转图像Demo和其源代码
💻 CPP
字号:
/**************************************************
 游戏主程序
Author:  LittleFish     QQ:93663886
E-Mail:  kittyfish_1981@yahoo.com.cn
Blog:    http://blog.csdn.net/kittyfish
真诚的期待你提出改良方法或程序BUG
**************************************************/


#include "GameApp.h"


//Window Program Entry:
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
	GameApp* pApp = new GameApp();
	pApp->SetCaption( _T("RotateImage Demo. Write By Fish") );
	pApp->SetSize( 640, 480 );
	pApp->SetHinstance( hInstance );
	g_pApplication = (GameApp*)pApp;
	pApp->Run();
	if( pApp != NULL )
		delete pApp; pApp = NULL;
}

LRESULT CALLBACK GameApp::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	return cApplication::MsgProc( hWnd, uMsg, wParam, lParam );
}

BOOL GameApp::Init()
{
	/*初始化DirectDraw*/
	CreateDirectDraw( FALSE, 640, 480 );
	if( g_pDirectDraw == NULL )
		return FALSE;

	m_iGameState = 0;

	/*加载图像*/
	m_grImage.CreateFromBitmap( _T("Image/fish.bmp") );

	m_pGrRotate = NULL;

	return TRUE;

}

BOOL GameApp::Shutdown()
{
	GetDirectDraw()->Release();
	SAFE_DELETE( g_pDirectDraw );

	m_grImage.Release();
	m_pGrRotate->Release();
	SAFE_DELETE( m_pGrRotate );

	return TRUE;
}

BOOL GameApp::Frame()
{
	static DWORD dwOldTime = GetTickCount();
	static DWORD dwDiffTime = 0;

	DWORD dwCurrTime = GetTickCount();
	dwDiffTime = dwCurrTime - dwOldTime;
	dwOldTime  = dwCurrTime;

	static int rotateAngle = 0;
	static int rotateMode  = 1;

	switch( m_iGameState )
	{
	case 0:
		{
			GetDirectDraw()->Frame(); //Frame Fisrt ,then PreFrame. :)
			GetDirectDraw()->ClearScreen();

			//源图
			g_pDirectDraw->LoadToBackSurface( &m_grImage, 0, 100 );
			//旋转相应角度后的图
			rotateAngle = (rotateAngle + 1)%360;
			//旋转一圈后,换另一种mode
			if( rotateAngle == 0 )
			{
				rotateMode = (rotateMode)%2 + 1;
			}
			SAFE_RELEASE( m_pGrRotate ); //清除上一次的图像
			m_pGrRotate = g_pDirectDraw->RotateImage( NULL, &m_grImage, rotateAngle*PI/180.0f, 0, FALSE, rotateMode );
			g_pDirectDraw->LoadToBackSurface( m_pGrRotate, 235, 100 );

			//集中输出文本,提高效率
			HDC hDC = g_pDirectDraw->BeginText( RGB(255,255,255) );
			g_pDirectDraw->TextOut( hDC, 0,   25, _T("Source Image:") );
			g_pDirectDraw->TextOut( hDC, 250, 25, _T("Destination Image:") );
			g_pDirectDraw->TextOut( hDC, 180, 50, _T("Rotate Image Demo,Write By Fish.") );
			g_pDirectDraw->TextOut( hDC, 180, 65, _T("Rotate Angle:[ %d ] Rotate Mode:[ %d ]"), rotateAngle, rotateMode );
			g_pDirectDraw->TextOut( hDC, 180, 80, _T("Speed:[%d]"), dwDiffTime );
			g_pDirectDraw->EndText( hDC );

		}
		break;

	default:break;
	}

	Sleep( 1 );
	return TRUE;
}

void GameApp::OnChar()
{
}

⌨️ 快捷键说明

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