📄 gameunit.cpp
字号:
// GameUnit.cpp: implementation of the GameUnit class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "GameUnit.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Game_Unit::Game_Unit(MainGame* pGame)
:GM_Unit(pGame->GetGameWorld()),
m_tex_status(pGame->GetGameWorld()->GetGsEngine()),
m_tex_speeking(pGame->GetGameWorld()->GetGsEngine())
{
m_pGame = pGame;
m_is_locate_control = FALSE;
m_is_auto_attack = FALSE;
m_aim_station_x = 0;
m_aim_station_y = 0;
m_aim_unit = 0;
m_lead_unit = 0;
m_ai_recover = 100;
m_ai_seq = 0;
m_is_player = FALSE;
m_str_name = "";
base_level = 2;
base_experience = 0;
base_life = 100;
base_mana = 100;
base_damage = 20;
base_strength = 20;
base_agility = 20;
//state
life = 100;
mana = 100;
status = 0;
count_pk = 0;
count_hunter = 0;
count_die = 0;
exp_level = 0;
exp_level_up = 0;
m_alpha_speeking = 0;
}
Game_Unit::~Game_Unit()
{
}
VOID Game_Unit::Cleanup()
{
std::list<UNIT_EFFECT_TIP*>::iterator it = m_list_effect_tip.begin();
while(it!=m_list_effect_tip.end())
{
if(*it)
{
delete(*it);
}
it = m_list_effect_tip.erase(it);
}
std::list<CGsSound*>::iterator it_sound = m_list_sound.begin();
while(it_sound!=m_list_sound.end())
{
if(*it_sound)
{
delete(*it_sound);
}
it_sound = m_list_sound.erase(it_sound);
}
std::list<PARTICLE_MAGIC*>::iterator it_pm = m_list_particle_magic.begin();
while(it_pm!=m_list_particle_magic.end())
{
if(*it_pm)
{
delete(*it_pm);
}
it_pm = m_list_particle_magic.erase(it_pm);
}
}
BOOL Game_Unit::Create(ID id, const char *szFile, float x, float y, float h)
{
BOOL bRet = GM_Unit::Create(id, szFile, x, y, h);
if(m_is_locate_control)
{
m_aim_station_x = x;
m_aim_station_y = y;
}
return bRet;
}
void Game_Unit::SetName(const char *strName)
{
m_str_name = strName;
update_name();
// update_status();
}
VOID Game_Unit::ReleaseSource()
{
m_tex_status.ReleaseObjects();
m_tex_speeking.ReleaseObjects();
return ;
}
HRESULT Game_Unit::RestoreSource()
{
m_tex_status.RestoreObjects();
// SetName(m_str_name.c_str());
update_name();
update_status();
m_tex_speeking.RestoreObjects();
return S_OK;
}
HRESULT Game_Unit::Render()
{
LONG x, y;
m_pWorld->GetOriginal(x,y);
if(m_pGame->m_want_unit_light)
{
m_pWorld->GetGsEngine()->PreparePaint (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, D3DTOP_MODULATE , D3DTOP_MODULATE);
m_pWorld->GetGsEngine()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE);
float light_rate=1.0f;
if(is_melee())
{
light_rate += (1.0f-abs(m_pAnimation->GetFinishPercent()-50.0f)/50.0f)*0.8f;
}
else if(is_flinch())
{
light_rate += (100.0f-m_pAnimation->GetFinishPercent())/100.0f*0.4f;
}
else if(is_death())
{
light_rate = (150.0f-m_pAnimation->GetFinishPercent())/150.0f*1.4f;
}
m_pWorld->GetGsEngine()->Render_PaintFast(m_fPosX-x, m_fPosY-y,
m_pGame->m_ani_light_shadow.GetCurrentFrame(),
0.0f, m_tall_rate*light_rate*250/64, m_tall_rate*light_rate*250/128,
0.15f);
if(m_bSelect)
{
m_pWorld->GetGsEngine()->Render_PaintFast(m_fPosX-x, m_fPosY-y,
m_pGame->m_ani_select_unit.GetCurrentFrame(),
0.0f, m_tall_rate*m_seize_x/60, m_tall_rate*m_seize_x/60,
1.0f);
}
}
if(m_id==m_pGame->GetControlUnit()->m_aim_unit)
{
m_pWorld->GetGsEngine()->PreparePaint();
float f_a = m_pWorld->GetGsEngine()->ValueCycle(0.0f, 1.0f, 0, 500, 1);
m_pWorld->GetGsEngine()->Render_PaintFast(m_fPosX-x, m_fPosY-y,
m_pGame->m_ani_select_unit.GetCurrentFrame(),
0.0f, m_tall_rate*m_seize_x/40*f_a, m_tall_rate*m_seize_x/40*f_a,
1.0f);
}
GM_Unit::Render();
m_pWorld->GetGsEngine()->PreparePaint();
m_pWorld->GetGsEngine()->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTFN_POINT );
m_pWorld->GetGsEngine()->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTFN_POINT );
m_pWorld->GetGsEngine()->Render_PaintFast(m_fPosX-x-100, m_fPosY-y-160*m_tall_rate, &m_tex_status, 0.0f, 1.0f, 1.0f, 1.0f);
if(m_alpha_speeking>0)
{
m_pWorld->GetGsEngine()->Render_PaintFast(m_fPosX-x, m_fPosY-y-200*m_tall_rate, &m_tex_speeking, 0.0f, 1.0f, 1.0f, m_alpha_speeking);
}
std::list<GSANI*>::iterator it_ani = m_list_ani_effect.begin();
while (it_ani!=m_list_ani_effect.end()) {
CGsTexture* pTex = (*it_ani)->GetCurrentFrame();
pTex->UpdateFromCache();
m_pWorld->GetGsEngine()->Render_PaintFast(m_fPosX-x, m_fPosY-y-50,
pTex,
0.0f,1.0f, 1.0f,
1.0f);
it_ani++;
}
std::list<UNIT_EFFECT_TIP*>::iterator it = m_list_effect_tip.begin();
while(it!=m_list_effect_tip.end())
{
UNIT_EFFECT_TIP* p_uet = *it;
if(p_uet)
{
//p_uet->tex.Clear(0xffffffff);
m_pWorld->GetGsEngine()->Render_PaintFast(p_uet->pos_x-x, p_uet->pos_y-y-p_uet->pos_h,
&p_uet->tex,
0.0f,p_uet->scale, p_uet->scale,
p_uet->alpha);
}
it++;
}
return S_OK;
}
HRESULT Game_Unit::Render2()
{
LONG x, y;
m_pWorld->GetOriginal(x,y);
std::list<PARTICLE_MAGIC*>::iterator it_pm = m_list_particle_magic.begin();
while(it_pm!=m_list_particle_magic.end())
{
(*it_pm)->particles.Render(GPOINT(-x,-y));
if((*it_pm)->p_ani)
{
(*it_pm)->p_ani->SetFaceTo((*it_pm)->angle);
(*it_pm)->p_ani->DrawFast(-x+(*it_pm)->pos_x, -y+(*it_pm)->pos_y-80*m_tall_rate);
}
it_pm++;
}
return S_OK;
}
VOID Game_Unit::OnMove()
{
query_update_state();
}
VOID Game_Unit::OnWait()
{
}
VOID Game_Unit::OnChangeRenderFlag(BOOL bRender)
{
if(bRender)
{
m_tex_status.CreateEx(200, 50);
m_tex_status.Clear(0);
m_tex_speeking.CreateEx(500, 30);
m_tex_speeking.SetBasePoint(GPOINT(250, 30));
m_tex_speeking.Clear(0);
update_name();
update_status();
}
else
{
m_tex_status.ReleaseObjects();
m_tex_speeking.ReleaseObjects();
}
return;
}
LONG Game_Unit::Update()
{
LONG ret = 0;
if(m_pWorld&&m_pWorld->GetGsEngine())
{
float fsec = m_pWorld->GetGsEngine()->m_dwPassTime/1000.0f;
//处理说话纹理的alpha
if(m_alpha_speeking>0)
{
m_alpha_speeking -= 0.3*fsec;
}
//处理冒数字效果
std::list<UNIT_EFFECT_TIP*>::iterator it = m_list_effect_tip.begin();
while(it!=m_list_effect_tip.end())
{
UNIT_EFFECT_TIP* p_uet = *it;
if(p_uet)
{
switch(p_uet->flag) {
case UNIT_EFFECT_FLAG_DAMAGE:
{//文字上升
p_uet->alpha -= fsec*0.35f;
p_uet->pos_h += fsec*50;
if(p_uet->alpha<=0)
{//删除
delete(p_uet);
it = m_list_effect_tip.erase(it);
continue;
}
}
break;
case UNIT_EFFECT_FLAG_CURE:
{//文字上抛
if(p_uet->alpha==1.0f)
p_uet->pos_h = 80;
p_uet->alpha -= fsec*0.5f;
p_uet->pos_h -= fsec*80;
if(p_uet->alpha<=0.5f)
{//删除
delete(p_uet);
it = m_list_effect_tip.erase(it);
continue;
}
}
break;
default:
{
p_uet->alpha -= fsec*0.5f;
if(p_uet->alpha>0.9f)
p_uet->pos_h += fsec*300;
else
p_uet->pos_h -= fsec*300;
if(p_uet->alpha<=0.8f)
{//删除
delete(p_uet);
it = m_list_effect_tip.erase(it);
continue;
}
}
break;
}
it++;
}
else
{
delete(p_uet);
it = m_list_effect_tip.erase(it);
}
}
//处理附加动画效果
std::list<GSANI*>::iterator it_ani = m_list_ani_effect.begin();
while (it_ani!=m_list_ani_effect.end()) {
if((*it_ani)==NULL || (*it_ani)->Update()<0)
{
delete(*it_ani);
it_ani = m_list_ani_effect.erase(it_ani);
}
else
{
it_ani++;
}
}
ret = GM_Unit::Update();
BOOL bUpdateArrow = FALSE;
std::list<PARTICLE_MAGIC*>::iterator it_pm = m_list_particle_magic.begin();
while(it_pm!=m_list_particle_magic.end())
{
PARTICLE_MAGIC* ppm = *it_pm;
if(ppm)
{
if(ppm->life>0)
{
Game_Unit* pUnit_obj = (Game_Unit*)m_pWorld->GetObject(ppm->ses.uid_victim);
float fa = CGsFunc::Math_GetPointToAngle(pUnit_obj->m_FlatX - ppm->pos_x, pUnit_obj->m_FlatY - ppm->pos_y);
if(abs(pUnit_obj->m_FlatX - ppm->pos_x)<50
&& abs(pUnit_obj->m_FlatY - ppm->pos_y)<50
)
{//魔法效果
ppm->life = 0;
if(ppm->ses.uid_action_type>=2000)
ppm->speed/=4;
}
if(ppm->ses.uid_action_type<1000)
{//普通效果
if(abs(fa-ppm->angle)>0.4)
{
ppm->life = 0;
}
if(ppm->life==0)
{
if(ppm->ses.flag_special!=ACTION_LOST)
{
ppm->p_ani = NULL;
ppm->speed = 0;
ppm->particles.SetSuppressed(TRUE);
}
fa = ppm->angle;
}
}
//else
ppm->angle = fa;
}
else
{
ppm->life -=m_pWorld->GetGsEngine()->m_dwPassTime;
if(ppm->life<-700
|| ((ppm->ses.uid_action_type<1000 && ppm->ses.flag_special!=ACTION_LOST)
&& ppm->particles.GetNumParticlesActive()<=0))
{
delete(ppm);
it_pm = m_list_particle_magic.erase(it_pm);
continue;
}
}
ppm->pos_x += ppm->speed*fsec*cos(ppm->angle);
ppm->pos_y += ppm->speed*fsec*sin(ppm->angle);
ppm->particles.SetLocation(D3DVECTOR(ppm->pos_x, ppm->pos_y-80, ppm->pos_y-80));
ppm->particles.Update(fsec);
if(ppm->p_ani)
bUpdateArrow = TRUE;
}
else
{
it_pm = m_list_particle_magic.erase(it_pm);
}
it_pm++;
}
if(m_list_particle_magic.size()>0)
{
SetRender(TRUE);
}
if(bUpdateArrow)
m_ani_arrow.Update();
//处理攻击效果
CaleDamage();
//声音
std::list<CGsSound*>::iterator it_sound = m_list_sound.begin();
while(it_sound!=m_list_sound.end())
{
if(*it_sound)
{
if((*it_sound)->IsFree())
{
delete(*it_sound);
it_sound = m_list_sound.erase(it_sound);
continue;
}
}
else
{
it_sound = m_list_sound.erase(it_sound);
continue;
}
it_sound++;
}
}
return ret;
}
VOID Game_Unit::CaleDamage(BOOL bTestAct)
{
if(bTestAct==FALSE || !(is_melee() || is_spell() || is_ranged()) || GetAnimation()->TestByPercent(50))
{//判断攻击效果帧
//if(bTestAct==FALSE || GetAnimation()->TestByPercent(50))
{//这里可以做多重攻击效果,简单起见,随便实现一次性攻击效果算了
std::list<STRUCT_EFFECT_SPECIFIC>::iterator it = m_list_effect_specific.begin();
while(it!=m_list_effect_specific.end())
{
if(it->uid_action_type>=100 && it->uid_action_type<1000
|| it->uid_action_type>=2000 )
{
add_magic_effect_specific(*it);
it = m_list_effect_specific.erase(it);
continue;
}
Game_Unit* pUnit_obj = (Game_Unit*)m_pWorld->GetObject(it->uid_victim);
if(pUnit_obj!=NULL)
{
base_experience += it->experience_alter;
switch(it->flag_special) {
case 1://打倒
case 2://打倒
case 3://打倒
{
// if(pUnit_obj->GetAnimation()==&pUnit_obj->m_ani_death)
// break;
//pUnit_obj->CaleDamage(FALSE);
if(!pUnit_obj->is_death())
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -