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

📄 engine.cpp

📁 diablo图形引擎例子
💻 CPP
字号:
// Engine.cpp: implementation of the Engine class.
//
//////////////////////////////////////////////////////////////////////


#include "Engine.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Engine::Engine()
{
	m_lpDirectDraw=NULL;
	m_lpMap=NULL;

}

Engine::~Engine()
{
	
}

bool Engine::Initialize(HWND hWnd)
{

	m_lpDirectDraw=new DirectDraw;
	if (!m_lpDirectDraw->Create(hWnd)) return false;

	m_lpMap=new Map;
	m_lpMap->LoadMapFile("default.map");
	m_lpMap->LoadMapCGL("default.cgl",m_lpDirectDraw->m_bColorMode);
	m_lpMap->CreateCharactar(m_lpDirectDraw->m_bColorMode);


	m_lpImageCursor=new ImageList;
	m_lpImageCursor->Create("system.cgl",m_lpDirectDraw->m_bColorMode,0);

	return true;
}

void Engine::UpdateFrame()
{
	
	POINT cpt;
	GetCursorPos(&cpt);
	m_lpMap->m_Cursor=cpt;

	WORD *lpBitmap=NULL;
	long  lPitch;
	
	//bool debug=true;
	bool debug=false;
	

	m_lpDirectDraw->CleanDDSBackbuffer(0);

	if (debug) 
	{
		lpBitmap = new WORD [DisplayMode_Width*DisplayMode_Height];
		lPitch=DisplayMode_Width;
	}
	else m_lpDirectDraw->Lock(lpBitmap,lPitch);


	//Draw Code here
	m_lpMap->DrawMapLayer(m_lpMap->m_lpCharactar->m_ix-64*6-32,-32*2+m_lpMap->m_lpCharactar->m_iy,lpBitmap,lPitch);

	
	POINT pt;
	GetCursorPos(&pt);

	m_lpImageCursor->Draw(0,pt.x,pt.y,lpBitmap,lPitch);


	if (debug) delete lpBitmap;
	else m_lpDirectDraw->UnLock();


	//m_lpDirectDraw->Flip();

	
	HDC dc;char temp[256];
	m_lpDirectDraw->m_lpDDSBackbuffer->GetDC(&dc);
	//SetBkMode(dc,TRANSPARENT);
	
	m_lpDirectDraw->Dump(temp);
	TextOut(dc,0,0,temp,strlen(temp));	
	sprintf(temp,"%d",m_lpMap->m_lpCharactar->m_iLookAroundTimeCount);
	TextOut(dc,100, 0, temp, strlen(temp));
	sprintf(temp,"%d %d",m_lpMap->m_Cursor.x,m_lpMap->m_Cursor.y);
	TextOut(dc,200, 0, temp, strlen(temp));
	int x,y;
	x=m_lpMap->m_Cursor.x;
	y=m_lpMap->m_Cursor.y;
	m_lpMap->ConvertPosition(x,y); 
	sprintf(temp,"%d %d",x,y);
	TextOut(dc,0, 60, temp, strlen(temp));

	m_lpMap->m_lpCharactar->Dump(temp);

	RECT rc;
	rc.left=0;rc.right=400;
	rc.top=20;rc.bottom=200+40;
	DrawText(dc,temp,strlen(temp),&rc,0);
	//TextOut(dc,0, 20, temp, strlen(temp));
	m_lpDirectDraw->m_lpDDSBackbuffer->ReleaseDC(dc);

	//for(int i=0;i<10000000;i++);


	

	//-------------------------//
	m_lpDirectDraw->Flip();
}

⌨️ 快捷键说明

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