gsg_particles.cpp
来自「混乱竞技场的全套代码,客户端资源可以网上搜」· C++ 代码 · 共 232 行
CPP
232 行
// GSG_Particles.cpp: implementation of the GSG_Particles class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "gstools.h"
#include "GSG_Particles.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
GSG_Particles::GSG_Particles(CGsEngine* pEngine)
:CGsGame(pEngine)
,m_particles(pEngine)
{
m_pos_grid = GPOINT(200,200);
m_pos_base = GPOINT(200,200);
m_pos_show = GPOINT(200,200);
m_pos_drag = GPOINT(0,0);
m_pos_base_fix = GPOINT(0,0);
m_color_base_grid = D3DRGBA(0.7f,0.7f,0.7f,0.5f);
m_bStartDrag = false;
m_key_style = "GSG_Particles";
}
GSG_Particles::~GSG_Particles()
{
}
BOOL GSG_Particles::Create()
{
if(FALSE==m_particles.Create((LPCSTR)g_pWizard->GetCurrentItemPath()))
{
return FALSE;
}
dlg_tools.Create(m_particles);
return TRUE;
}
LRESULT GSG_Particles::MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
return CGsGame::MsgProc( uMsg, wParam, lParam );
}
ID GSG_Particles::OnMouseMove(UINT nFlags, GPOINT point)
{
switch(nFlags)
{
case MK_RBUTTON:
{
if(!m_bStartDrag)
break;
m_pos_base += (point - m_pos_drag);
m_pos_drag = point;
m_pos_grid = m_pos_base;
m_pos_show = m_pos_base - m_pos_base_fix;
}
break;
case MK_LBUTTON:
// {
// if(!m_bStartDrag)
// break;
// m_pos_base_fix += (point - m_pos_drag);
// m_pos_base += (point - m_pos_drag);
// m_pos_drag = point;
// m_pos_grid = m_pos_base;
// //m_pos_show = m_pos_base + point_s;
// }
break;
}
return CGsGame::OnMouseMove(nFlags, point);
}
ID GSG_Particles::OnLButtonDown( UINT nFlags, GPOINT point )
{
m_bStartDrag = true;
m_pos_drag = point;
return CGsGame::OnLButtonDown( nFlags, point );
}
ID GSG_Particles::OnLButtonUp( UINT nFlags, GPOINT point )
{
return CGsGame::OnLButtonUp( nFlags, point );
}
ID GSG_Particles::OnLButtonDbClk( UINT nFlags, GPOINT point )
{
return CGsGame::OnLButtonDbClk( nFlags, point );
}
ID GSG_Particles::OnRButtonDown( UINT nFlags, GPOINT point )
{
m_bStartDrag = true;
m_pos_drag = point;
return CGsGame::OnRButtonDown( nFlags, point );
}
ID GSG_Particles::OnRButtonUp( UINT nFlags, GPOINT point )
{
return CGsGame::OnRButtonUp( nFlags, point );
}
ID GSG_Particles::OnRButtonDbClk( UINT nFlags, GPOINT point )
{
return CGsGame::OnRButtonDbClk( nFlags, point );
}
ID GSG_Particles::OnMouseWheel(UINT nFlags, short zDelta, GPOINT point)
{
return CGsGame::OnMouseWheel(nFlags, zDelta, point);
}
ID GSG_Particles::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
return CGsGame::OnChar(nChar, nRepCnt, nFlags);
}
ID GSG_Particles::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
return CGsGame::OnKeyDown(nChar, nRepCnt, nFlags);
}
ID GSG_Particles::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
return CGsGame::OnKeyUp(nChar, nRepCnt, nFlags);
}
FLAG GSG_Particles::Update(DWORD dwPassTime)
{
m_particles.Update(dwPassTime/1000.0f);
D3DVECTOR pos;// = m_particles.GetLocation();
switch(dlg_tools.m_nAction)
{
case 1:
pos.x = m_pEngine->ValueCycle(-dlg_tools.m_preview_length, dlg_tools.m_preview_length, 0, dlg_tools.m_preview_speed, 1);
pos.y = 0.0f;
pos.z = 0.0f;
break;
case 2:
{
float angle = m_pEngine->ValueLoop(0, const_2_PI, 0, dlg_tools.m_preview_speed*const_PI, 1);
pos.x = dlg_tools.m_preview_length * cosf(angle);
pos.y = 0.0f;
pos.z = 2*dlg_tools.m_preview_length * sinf(angle);
}
break;
case 3:
pos.x = m_pEngine->ValueCycle(-dlg_tools.m_preview_length, dlg_tools.m_preview_length, 0, dlg_tools.m_preview_speed, 1);
pos.y = 0.0f;
pos.z = 0.0f;
break;
default:
pos.x = 0.0f;
pos.y = 0.0f;
pos.z = 0.0f;
break;
}
m_particles.SetLocation(pos);
return 0;
}
HRESULT GSG_Particles::Render()
{
m_pEngine->PreparePaint();//D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, D3DTOP_MODULATE4X, D3DTOP_MODULATE);
// m_pEngine->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE);
// m_pEngine->PreparePaint();
m_particles.Render(m_pos_grid);
CGsSurface* pBackSurface = m_pEngine->GetBackSurface();
GRECT rc = pBackSurface->GetRect();
m_pEngine->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTFN_POINT );
m_pEngine->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTFN_POINT );
m_pEngine->Render_DrawLine(m_pos_grid.x, rc.top, m_pos_grid.x, rc.bottom, m_color_base_grid);
m_pEngine->Render_DrawLine(rc.left, m_pos_grid.y, rc.right, m_pos_grid.y, m_color_base_grid);
return S_OK;
}
HRESULT GSG_Particles::Draw(CGsSurface *pSurface)
{
char buffer[100];
sprintf( buffer, "%u", m_particles.GetNumParticles());
pSurface->DrawTextDirect(NULL, buffer, 100, 50, RGB(255,255,255), RGB(1,1,1));
return S_OK;
}
VOID GSG_Particles::Cleanup()
{
CGsGame::Cleanup();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?