Esempio n. 1
0
int _tmain(int argc, _TCHAR* argv[])
{
	// 注册错误回调函数
	FKAISystem::RegisterErrorMsgReceiver( OutPut );
	// 初始化状态机表
	FKAISystem::SetStateFilesDirectory( "Bin/Data/AIScript" );


	CMonster* pMonster = new CMonster();
	pMonster->Init("状态机表名称");
	for( ;; )
	{
		// 获取帧间隔时间
		static float lastTime = 0;
		lastTime = g_fAccumTime;
		g_fAccumTime = (float)timeGetTime() / 1000.0f;
		g_fTimeFromLastFrame = g_fAccumTime - lastTime;

		//最低帧数控制
		if (g_fTimeFromLastFrame>0.2f)
			g_fTimeFromLastFrame = 0.2f;

		// 每帧间隔CPU休眠时间
		if(g_dwSleepTime > 0) Sleep(g_dwSleepTime);

		pMonster->Update( g_fTimeFromLastFrame );
	}
	pMonster->Destory();
	return 0;
}
Esempio n. 2
0
void CGameProc::Render(float fElapsedTime)
{
	int nCnt;
	if(m_pD3DDevice == NULL)
    {
		return;
    }
	
	g_pPlayer->Update(fElapsedTime);

	m_xSkillWnd.Update(fElapsedTime);

	m_xMonsterList.MoveCurrentToTop();
	for (nCnt=0;nCnt<m_xMonsterList.GetCounter();nCnt++)
	{
		CMonster *pMonster;
		pMonster=m_xMonsterList.GetCurrentData();
		pMonster->Update(fElapsedTime);
		m_xMonsterList.MoveNextNode();
	}

	m_pWater->Update(fElapsedTime);

 	if (g_pPlayer->m_pTargetInfo)
 		m_pRoleInfo->Update(&g_pPlayer->m_xPlayInfo,g_pPlayer->m_pTargetInfo,true);
 	else
    	m_pRoleInfo->Update(&g_pPlayer->m_xPlayInfo,g_pPlayer->m_pTargetInfo,false);
	
	//Clear the back buffer and depth buffer
    m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, NULL, 1.0f, 0);
    m_pD3DDevice->BeginScene();

	g_pCamera->Setup3DCamera();
	
	g_pPlayer->Render();

	float i;
	m_xMonsterList.MoveCurrentToTop();
	for (nCnt=0;nCnt<m_xMonsterList.GetCounter();nCnt++)
	{
		CMonster *pMonster;
		pMonster=m_xMonsterList.GetCurrentData();
		if (nCnt==2)
		{
			pMonster->m_pMonsterMesh->SetPosition(D3DXVECTOR3(pMonster->m_xMonsterInfo.x,m_pTerrain->getHeight(pMonster->m_xMonsterInfo.x,pMonster->m_xMonsterInfo.z),pMonster->m_xMonsterInfo.z));
			i=pMonster->m_fAngel;
		}
		pMonster->Render();
		m_xMonsterList.MoveNextNode();
	}
	
	D3DXVECTOR3 playerPos;
	g_pPlayer->GetPos(&playerPos);
	m_pSkyBox->Render(playerPos);
	
	D3DXMATRIX matViewProj;
    g_pCamera->GetViewProj(&matViewProj);
  m_pTerrain->Render(&matViewProj,false);	 
	
	// 绘制透明物体
    m_pWater->Render();

	g_pCamera->Setup2DCamera();

	g_pChatPopWnd->Render();
	m_xSkillWnd.Render();
	m_pRoleInfo->Render();

	

	char buf[255];
	if (g_pPlayer->m_pPlayerMesh->m_bHightlight)
	{
       g_pFont->DrawText("打开深度光照",0,0,D3DCOLOR_XRGB(255,255,0));
	}
	D3DXVECTOR3 vPos;
	g_pCamera->GetCameraPos(&vPos);



	sprintf(buf,"坐标%f %f %f\n 摄像机位置 %f %f %f	\n 鼠标坐标%d,%d \n%d %d\n%f",playerPos.x,playerPos.z,fElapsedTime,vPos.x,vPos.y,vPos.z,m_pt.x,m_pt.y
	,g_pChatPopWnd->m_nTaskState,g_pChatPopWnd->m_nPageIndex,i/D3DX_PI);
   g_pFont->DrawText(buf,0,512,D3DCOLOR_XRGB(0,0,0));

   if (g_szBuf!=NULL&&m_xSkillWnd.m_xLock.bLock)
   {
	      g_pFont->DrawText(g_szBuf,456,150,D3DCOLOR_XRGB(0,0,0));
   }

    m_pD3DDevice->EndScene();
    //Filp the back and front buffers so that whatever has been rendered on the back buffer
    //will now be visible on screen (front buffer).
    m_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}