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

📄 gamestart.cpp

📁 3D俄罗斯方块源码.rar
💻 CPP
字号:
//--------------------------------------------------------------
/**\!File
  *
  *File name:GAMESTART.cpp
  *
  *His:add by honghaier @2004/5/7
  *
  *Desc:游戏开始部分类
  */
//---------------------------------------------------------------
#include "GameStart.h"
#include "dxutil.h"
int g_tile=0;
void CALLBACK TimerProc1(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime);
//---------------------------------------------------------------
CGameStart::CGameStart()
{
	m_menu=NULL;
	m_pFont=NULL;
}
CGameStart::~CGameStart()
{
	  SAFE_DELETE(m_menu);
	   SAFE_DELETE(m_pFont);
	   for(int i=0;i<8;i++)
	   {
		   SAFE_DELETE(m_wood[i]);
	   }
}
bool CGameStart::init(HWND _hWnd,LPDIRECT3DDEVICE8 pd3dDevice,int _x,int _y)
{   
	m_hWnd=_hWnd;
	m_pd3dDevice=pd3dDevice;
	m_personnum=1;
	m_align=1;
	m_row=0;
	m_leve=1;
	m_type=false;
	m_x=_x;
	m_y=_y;
	m_isshownext=true;
	m_menu=new CGameMenu(pd3dDevice,"GAME MENU");
	m_menu->SetXY(_x,_y);
	m_menu->Add("1 PLAYER");
	m_menu->Add("2 PLAYER");
	m_menu->Add("Configuration");
	m_menu->Add("ReadMe");
	
	lstrcpy( m_strFont, _T("Arial") );
    m_dwFontSize  = 20;
    m_pFont= new CD3DFont( m_strFont, m_dwFontSize );
	m_pFont->InitDeviceObjects(m_pd3dDevice);
	m_pFont->RestoreDeviceObjects();
	//----------------------------------
	for(int i=0;i<8;i++)
	{
		m_wood[i]=new CCuboid(m_pd3dDevice);
		m_wood[i]->SetSize(50.0,50.0,50.0);
		char filename[50];
		wsprintf(filename,"tex\\wood%d.jpg",i);
		m_wood[i]->SetTexture(filename);
	}
	//---------------设置SETCONTROL界面-------------------
	if(FAILED(m_ControlGUI.init(_hWnd,pd3dDevice)))return false;
	if(FAILED(m_OtherGUI.init(pd3dDevice)))return false;
	m_ShowContorl=false;
	m_ShowOther=false;
	return true;
}
void CGameStart::Render()
{
	if(m_pd3dDevice == NULL)
    {
        return;
    }
    m_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    m_pd3dDevice->BeginScene();
	//-----------------------------------
    D3DXMATRIX matView;
    D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3(0.0f,0.0f,-300.0f),		//Camera Position
		&D3DXVECTOR3(0.0f,0.0f, 0.0f),		//Look At Position
		&D3DXVECTOR3(0.0f, 1.0f, 0.0f));		//Up Direction
    m_pd3dDevice->SetTransform(D3DTS_VIEW, &matView);
    D3DXMATRIX matProj;
    D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.0f, 1.0f, 800.0f);
    m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);
	
	if(m_ShowContorl==true)
	{
		m_ControlGUI.Render();
		//--------------
		RenderTowWood();
	}
	else
	{
		if(m_ShowOther==true)
		{
			m_OtherGUI.Render();
		}
		else
		{
			RenderWood();
			m_menu->Render();
		}
	}
	//-----------------------------------
	
	//-------------------------------------
    m_pd3dDevice->EndScene();
    m_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}
bool CGameStart::GameLoop(int *_where)
{
    SetTimer(m_hWnd,66,2000,TimerProc1);		
    MSG msg; 
    BOOL fMessage;
    PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
    while(1)
    {
        fMessage = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);
		
        if(fMessage)
        {
            //Process message
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
		else
		{
			Render();
			if(*_where==2)
			{
				if(CleanRender())
				{
					break;
				}
				KillTimer(m_hWnd,66);
			}			
		}
	}
	return true;
}
bool CGameStart::CleanRender()
{
	if(m_pd3dDevice == NULL)
    {
        return false;
    }
    m_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    m_pd3dDevice->BeginScene();
    m_pd3dDevice->EndScene();
    m_pd3dDevice->Present(NULL, NULL, NULL, NULL);
	return true;
}
void CGameStart::RenderWood()
{
	D3DXMATRIX matWorld2;
	D3DXMatrixIdentity(&matWorld2);
	D3DXMatrixRotationY( &matWorld2, timeGetTime()/1000.f );
	m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld2);
	m_wood[g_tile]->Render();
}
void CGameStart::RenderTowWood()
{
	D3DXMATRIX matWorld;
	D3DXMatrixIdentity(&matWorld);
	D3DXMatrixTranslation(&matWorld,-170,60,500);
	m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld);
    D3DXMATRIX matWorld2;
	D3DXMatrixIdentity(&matWorld2);
	D3DXMatrixRotationY( &matWorld2, timeGetTime()/1000.f );
	D3DXMatrixMultiply(&matWorld2,&matWorld2,&matWorld);
	m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld2);
	m_wood[g_tile]->Render();
	D3DXMatrixIdentity(&matWorld);
	D3DXMatrixTranslation(&matWorld,110,60,500);
	m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld);
	D3DXMatrixIdentity(&matWorld2);
	D3DXMatrixRotationY( &matWorld2, timeGetTime()/1000.f );
	D3DXMatrixMultiply(&matWorld2,&matWorld2,&matWorld);
	m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld2);
	m_wood[g_tile]->Render();
}
void CGameStart::ShowSetControlGUI()
{
	m_ShowOther=false;
	m_ShowContorl=!m_ShowContorl;
	
}
void CGameStart::ShowOtherGUI()
{
	m_ShowContorl=false;
	m_ShowOther=true;
}
/**!\brief
*\param a:级别
*\parma b:行数
*\param c:align
*\param d:是否显示
*\param e:是否增加
*/
void CGameStart::SetOther(int a,int b,int c,bool _b1,bool _b2)
{
	m_leve=a;
	m_row=b;
	m_align=c;
	m_isshownext=_b1;
	m_type=_b2;//是否增加
}
void CALLBACK TimerProc1(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
	switch(nTimerid)
	{
	case 66: 
		g_tile++;
		if(g_tile==8)
		{
			g_tile=0;
		}
		break;
	}
}

⌨️ 快捷键说明

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