📄 bubble.cpp
字号:
// Bubble.cpp: implementation of the CBubble class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Bubble.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBubble::CBubble(CGsEngine* pEngine)
{
m_color = D3DRGBA(128,128,128,255);
m_bubble_type = 0;
m_pEngine = pEngine;
m_pos_x = 0;
m_pos_y = 0;
m_tick_create = 0;
m_alpha = 1.0f;
}
CBubble::~CBubble()
{
Cleanup();
}
void CBubble::Cleanup()
{
std::list<BUBBLE_EFFECT*>::iterator it = m_lst_ani.begin();
while(it!=m_lst_ani.end())
{
if(*it)
{
if((*it)->ptr_effect)
delete((*it)->ptr_effect);
delete(*it);
}
it = m_lst_ani.erase(it);
}
}
HRESULT CBubble::Render(LONG x, LONG y, float fScale, BOOL bColor)
{
std::list<BUBBLE_EFFECT*>::iterator it = m_lst_ani.begin();
float fangle = m_pEngine->ValueCycle(-const_PI_DIV_4/2, const_PI_DIV_4/2, m_tick_create, 700);
float fs = m_pEngine->ValueCycle(fScale/BUBBLE_BMP_SIZE*0.95f, fScale/BUBBLE_BMP_SIZE*1.05f, m_tick_create, 800);
float fx = x + m_pos_x*fScale;
float fy = y - m_pos_y*fScale;
if(m_alpha!=1.0f)
{
fs /= (0.4+m_alpha*0.7);
}
//m_pEngine->PreparePaint(D3DBLEND_SRCCOLOR, D3DBLEND_ONE);
m_pEngine->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCCOLOR );
m_pEngine->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE );
while(it!=m_lst_ani.end())
{
if (bColor)
{
(*it)->ani.Draw(fx, fy, 0.0f, fs, fs, m_alpha, fangle, m_color);
}
else
{
float fc = m_pEngine->ValueCycle(1.0f, 6.99f, m_tick_create, 1000);
(*it)->ani.Draw(fx, fy, 0.0f, fs, fs, 1.0f, fangle, CBubble::BubbleColor(fc));
}
if((*it)->ptr_effect)
{
(*it)->ptr_effect->SetLocation(D3DVECTOR(fx, fy, fy));
(*it)->ptr_effect->Update();
if((*it)->ptr_effect->GetSuppressed() && (*it)->ptr_effect->GetNumParticlesActive()<=0)
{
SAFE_DELETE((*it)->ptr_effect);
}
else
{
(*it)->ptr_effect->Render(GPOINT(0,0));
}
}
it++;
}
if (m_card_type>0)
{
CGsTexture* pTex = g_get_ani_card(m_card_type);
if (pTex)
{
m_pEngine->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA );
m_pEngine->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA );
fangle = m_pEngine->ValueCycle(-const_PI_DIV_4, const_PI_DIV_4, m_tick_create, 2000);
m_pEngine->Render_Paint(fx, fy, pTex, 0.0f, 0.36f, 0.36f, 0.9f, fangle);
}
}
return S_OK;
}
BOOL CBubble::Create(BYTE bubble)
{
if(m_pEngine==NULL)
return FALSE;
Cleanup();
m_bubble_type = bubble;
BUBBLE_EFFECT* pbf = new BUBBLE_EFFECT;
pbf->ani.SetGsEngine(m_pEngine);
pbf->ani.Create("bubble.bmp");
// pbf->ani.GetTextureGroup()->m_base_point = GPOINT(64,64);
pbf->ptr_effect = NULL;
m_lst_ani.push_back(pbf);
m_tick_create = m_pEngine->m_dwEngineTime;
SetBubbleType(bubble);
SetStop(TRUE);
return TRUE;
}
void CBubble::SetPos(int x, int y)
{
m_pos_x = x;
m_pos_y = y;
}
void CBubble::SetStop(BOOL bStop)
{
std::list<BUBBLE_EFFECT*>::iterator it = m_lst_ani.begin();
while(it!=m_lst_ani.end())
{
if(*it)
{
if((*it)->ptr_effect)
{
(*it)->ptr_effect->SetSuppressed(bStop);
}
else if(bStop==FALSE)
{
// if(m_bubble_type%2)
// {
// (*it)->ptr_effect = new CGsParticleEmitter(m_pEngine);
// (*it)->ptr_effect->Create("particles\\bb");
// }
// else
// {
// (*it)->ptr_effect = new CGsParticleEmitter(m_pEngine);
// (*it)->ptr_effect->Create("particles\\bb1");
// }
}
}
it++;
}
}
void CBubble::SetBubbleType(BYTE bubble_type)
{
m_bubble_type = bubble_type;
m_color = CBubble::BubbleColor(bubble_type);
m_card_type = (bubble_type)/10;
}
D3DCOLOR CBubble::BubbleColor(BYTE type)
{
switch(type%10)
{
case 1:
return D3DRGBA(1,1,1,1);//白
case 2:
return D3DRGBA(200,8,8,255);//兰
case 3:
return D3DRGBA(1.0f,0.5f,1.0f,1.0f);//紫
case 4:
return D3DRGBA(32,32,255,255);//金
case 5:
return D3DRGBA(200,32,255,255);//绿
case 6:
return D3DRGBA(200,80,8,255);//蓝
// case 7:
// m_color = D3DRGBA(0.5f,0.2f,0,1);//橙
// break;
// case 8:
// m_color = D3DRGBA(0.8f,0.3f,0.1f,1);//红
// break;
// case 9:
// m_color = D3DRGBA(0.2f,0.2f,0.2f,1.0f);
// break;
case 0:
default:
return D3DRGBA(0.7f,0.3f,0.2f,1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -