📄 maingame.cpp
字号:
{
if (m_ptr_player==pPlayer || m_ptr_player==pPlayer_obj)
{
add_skill_effect(src, dest,
"ani\\mana.txg",
"particles\\magic_3");
}
play_sound("bubble_sound\\heal");
}
break;
case ENUM_HANDLE_KILL: //杀
{
add_skill_effect(src, dest,
"ani\\magic.txg",
"particles\\magic_1");
play_sound("bubble_sound\\use_bubble");
play_sound("bubble_sound\\use_bubble");
play_sound("bubble_sound\\use_bubble");
}
break;
case ENUM_HANDLE_POP_BIG: //大消泡泡
{
add_skill_effect(src, dest,
"ani\\mana.txg",
"particles\\magic_3");
play_sound("bubble_sound\\heal");
play_sound("bubble_sound\\heal");
play_sound("bubble_sound\\heal");
}
break;
case ENUM_HANDLE_SUBTRACT_COIN: //扣掉一分
{
char str[50];
sprintf(str, "-%d", abs(pSHP->score - m_map_user[pSHP->user].n_score));
pPlayer_obj->add_effect_tip(str,
GPOINT(0, pPlayer_obj->GetHeight()/2),
GPOINT(pPlayer_obj->GetWidth(), pPlayer_obj->GetHeight()+3),
RGBA_MAKE(255, 25, 0, 250),
1.7f
);
if (m_ptr_player==pPlayer || m_ptr_player==pPlayer_obj)
{
add_skill_effect(src, dest,
"ani\\magic.txg",
"particles\\magic_1");
play_sound("bubble_sound\\use_bubble");
}
play_sound("bubble_sound\\use_bubble");
}
break;
case ENUM_HANDLE_BONUS_COIN: //奖励金币
{
char str[50];
sprintf(str, "+%d", abs(pSHP->score - m_map_user[pSHP->user].n_score));
pPlayer_obj->add_effect_tip(str,
GPOINT(0, pPlayer_obj->GetHeight()/2),
GPOINT(pPlayer_obj->GetWidth(), pPlayer_obj->GetHeight()+3),
RGBA_MAKE(0,205,15, 250),
1.7f
);
if (m_ptr_player==pPlayer || m_ptr_player==pPlayer_obj)
{
add_skill_effect(src, dest,
"ani\\mana.txg",
"particles\\magic_3");
play_sound("bubble_sound\\heal");
play_sound("bubble_sound\\heal");
}
play_sound("bubble_sound\\heal");
}
break;
}
}
}
if(pPlayer)
{
pPlayer->num_bubble_store = pSHP->bubble_good;
pPlayer->num_bubble_bad = pSHP->bubble_bad;
if (pSHP->score!=m_map_user[pSHP->user].n_score)
{
m_map_user[pSHP->user].n_score = pSHP->score;
if(pPlayer)
{
int index = GetPlayerIndex(pSHP->user);
if(index>=0)
{
pPlayer->update_user_data(index, &m_map_user[pSHP->user]);
}
}
}
}
if(pPlayer_obj)
{
pPlayer_obj->num_bubble_store = pSHP->bubble_good_obj;
pPlayer_obj->num_bubble_bad = pSHP->bubble_bad_obj;
}
}
break;
case GSP_UPDATE_STATE:
{
ULONG uid = ptr_packet->read32();
CPlayer* pPlayer = GetPlayer(uid);
if(pPlayer)
{
pPlayer->m_state = *(ENUM_PLAYER_STATE*)ptr_packet->readData();
if (pPlayer->m_state==PLAYER_STATE_WIN)
{
if (pPlayer!=m_ptr_player)
{
play_sound("bubble_sound\\end_lost");
}
m_bk_music.SetStreamSource("bubble_sound\\wait");
m_bk_music.Play();
m_bk_music.SetLooping();
m_is_playing = FALSE;
}
else if (pPlayer->m_state==PLAYER_STATE_PLAYING)
{
m_is_playing = TRUE;
m_game_start_time = 0;
}
if (pPlayer==m_ptr_player)
{
switch(pPlayer->m_state) {
case PLAYER_STATE_WIN:
play_sound("bubble_sound\\end");
break;
case PLAYER_STATE_LOST:
play_sound("bubble_sound\\lost");
break;
case PLAYER_STATE_READY:
play_sound("bubble_sound\\ready");
update_game_clock(0);
break;
case PLAYER_STATE_PLAYING:
play_sound("bubble_sound\\start");
//m_bk_music.SetStreamSource("bubble_sound\\play");
m_bk_music.Stop();
m_bk_music.SetLooping(FALSE);
break;
default:
break;
}
}
}
}
update_ui();
break;
}
}
int MainGame::GetPlayerIndex(ULONG id_user)
{
for (int i=0; i<NUM_CHAIR; i++)
{
if(m_index[i]>=0 && player[m_index[i]]==id_user)
return i;
}
return -1;
}
void MainGame::add_skill_effect(GPOINT pt_src, GPOINT pt_dest, LPCSTR str_effect, LPCSTR str_particles)
{
if (str_effect==NULL)
{
return;
}
_EFFECT_SKILL* pbf = new _EFFECT_SKILL;
pbf->ani.SetGsEngine(m_pEngine);
pbf->ani.Create(str_effect);
pbf->pt_src = pt_src;
pbf->pt_dest = pt_dest;
pbf->start_time = m_pEngine->m_dwEngineTime;
pbf->ptr_effect = NULL;
if (str_particles!=NULL && str_particles[0]!=0)
{
pbf->ptr_effect = new CGsParticleEmitter(m_pEngine);
if(!pbf->ptr_effect->Create(str_particles))
SAFE_DELETE(pbf->ptr_effect);
}
m_lst_effect_skill.push_back(pbf);
}
STRUCT_ADD_USER* MainGame::GetUser(ULONG idUser)
{
std::map<ULONG, STRUCT_ADD_USER>::iterator it = m_map_user.find(idUser);
if (it!=m_map_user.end())
{
return &it->second;
}
return NULL;
}
void MainGame::update_ui()
{
CGsUIPanel* panel = m_pEngine->FindUIFromName("talk");
if (panel)
{
STRUCT_ADD_USER* ptr_user = GetUser(m_id_player_talk);
if (m_id_player_talk==0 || ptr_user==NULL)
{
m_is_broadcast = TRUE;
}
if (m_is_broadcast )
{
panel->SetCaption("对所有人说:");
}
else
{
char str[100];
sprintf(str, "对[%s]说:", ptr_user->str_name);
panel->SetCaption(str);
}
}
switch(GetMode()) {
case ENUM_GAME:
update_ui_game();
break;
case ENUM_LOBBY:
update_ui_lobby();
break;
}
}
void MainGame::update_ui_game()
{
// if (GetMode()==ENUM_GAME)
{
CGsUIPanel* pPanel_btn_ready = m_pEngine->FindUIFromName("ready");
CGsUIPanel* pPanel_btn_start = m_pEngine->FindUIFromName("start");
if(m_is_playing)
{
pPanel_btn_ready->SetEnable(FALSE);
pPanel_btn_start->SetEnable(FALSE);
}
else
{
pPanel_btn_ready->SetEnable(TRUE);
for (int i=0; i<NUM_CHAIR; i++)
{
if (player[i] && m_array_player[i].GetState()!=PLAYER_STATE_READY)
{
pPanel_btn_start->SetEnable(FALSE);
return;
}
}
if (m_ptr_player)
{
pPanel_btn_start->SetEnable(TRUE);
}
}
}
}
void MainGame::update_ui_lobby()
{
// if (GetMode()==ENUM_LOBBY)
{
CGsUIPanel* pPanel_btn_ok = m_pEngine->FindUIFromName("lobby_ok");
if (pPanel_btn_ok)
{
pPanel_btn_ok->SetEnable(m_index_table_select>0);
}
CGsUIPanel* pPanel_num_user = m_pEngine->FindUIFromName("人数");
if (pPanel_num_user)
{
pPanel_num_user->SetCaption(m_map_user.size()-1);
}
CGsUIPanel* pPanel_table_left = m_pEngine->FindUIFromName("lobby_left");
if (pPanel_table_left)
pPanel_table_left->SetEnable(m_page_table_select>=3);
CGsUIPanel* pPanel_table_right = m_pEngine->FindUIFromName("lobby_right");
if (pPanel_table_right)
pPanel_table_right->SetEnable(m_page_table_select<MAX_TABLE_NUM - NUM_TABLE_IN_LINE*2);
CGsUIPanel* pPanel_player_left = m_pEngine->FindUIFromName("player_left");
if (pPanel_player_left)
pPanel_player_left->SetEnable(m_page_player_select>0);
CGsUIPanel* pPanel_player_right = m_pEngine->FindUIFromName("player_right");
if (pPanel_player_right)
pPanel_player_right->SetEnable(m_page_player_select+6<=m_map_user.size());
}
}
BOOL MainGame::update_game_clock(ULONG game_time)
{
char str_time[100];
sprintf(str_time, "%02d:%02d", ((game_time/1000)/60)%60, (game_time/1000)%60);
m_tex_game_time.Clear(0);
GRECT rc(0,0,64,32);
HFONT fnt = CGsFunc::Font_QuickCreateFont(8 , NULL, -1, FALSE, FALSE, FALSE);
m_tex_game_time.DrawText(fnt,
str_time,
&rc,
64,
32,
DT_CENTER|DT_SINGLELINE|DT_VCENTER,
RGBA_MAKE(255,255,255, 195)
);
::DeleteObject(fnt);
return TRUE;
}
HRESULT MainGame::Render_game()
{
HRESULT hr;
m_pEngine->PreparePaint();
m_ani_dreamland.DrawFast(0,0);
if(m_index[0]>=0 && player[m_index[0]]>0)
{
m_array_player[m_index[0]].Render(655, 500);
}
for(int i=1; i<NUM_CHAIR; i++)
{
if(m_index[i]>=0 && player[m_index[i]]>0)
{
m_array_player[m_index[i]].Render(76+149*((i-1)%3), 290 + 279*(int)((i-1)/3));
}
}
if(m_ptr_player)
{
GRECT rc(490, 100, 520, 255);
m_pEngine->PreparePaint();
m_pEngine->Render_DrawRectEx(&rc, TRUE,
D3DRGBA(0.0f, 0.0f, 0.7f, 0.5f), D3DRGBA(0.0f, 0.0f, 0.7f, 0.5f),
D3DRGBA(0.0f, 0.0f, 0.7f, 0.8f), D3DRGBA(0.0f, 0.0f, 0.7f, 0.8f));
m_pEngine->PreparePaint(D3DBLEND_SRCCOLOR, D3DBLEND_INVSRCCOLOR);
//画能量泡泡
float fangle = m_pEngine->ValueCycle(-const_PI_DIV_4/2, const_PI_DIV_4/2, 0, 1000);
for(int i=0; i<(m_ptr_player->num_bubble_store/64)%8; i++)
{
m_ani_bubble.Draw(498, 120 + i*30, 0.0f, 13.0f/BUBBLE_BMP_SIZE, 13.0f/BUBBLE_BMP_SIZE, 1.0f, fangle, D3DRGBA(1.0f,0.5f,1.0f,1.0f));
}
for(i=0; i<(m_ptr_player->num_bubble_store/8)%8; i++)
{
m_ani_bubble.Draw(504, 120 + i*20, 0.0f, 9.0f/BUBBLE_BMP_SIZE, 9.0f/BUBBLE_BMP_SIZE, 1.0f, fangle, D3DRGBA(1.0f,1.0f,1.0f,255));
}
for(i=0; i<m_ptr_player->num_bubble_store%8; i++)
{
m_ani_bubble.Draw(510, 120 + i*16, 0.0f, 7.0f/BUBBLE_BMP_SIZE, 7.0f/BUBBLE_BMP_SIZE, 1.0f, fangle, D3DRGBA(200,8,8,255));
}
for (i=0; i<m_ptr_player->num_bubble_bad/5; i++)
{
m_ani_bubble.Draw(768 - i*20, 505, 0.0f, 9.0f/BUBBLE_BMP_SIZE, 9.0f/BUBBLE_BMP_SIZE, 1.0f, fangle, D3DRGBA(1.0f,0.5f,1.0f,0.5f));
}
for(i=0; i<m_ptr_player->num_bubble_bad%5; i++)
{
m_ani_bubble.Draw(765 - i*20, 490, 0.0f, 7.0f/BUBBLE_BMP_SIZE, 7.0f/BUBBLE_BMP_SIZE, 1.0f, fangle, D3DRGBA(200,8,8,255));
}
}
m_pEngine->PreparePaint();
hr = RenderUI();
STRUCT_ADD_USER* pUser = GetUser(m_id_player);
if(pUser && pUser->n_score>0 &&
m_ptr_player && m_is_playing &&
(m_ptr_player->GetState()==PLAYER_STATE_LOST || m_ptr_player->num_bubble_store>=8 && m_ptr_player->GetState()==PLAYER_STATE_PLAYING))
{
m_pEngine->PreparePaint();
m_pEngine->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
int power_limit = 500;
if (m_ptr_player->GetState()==PLAYER_STATE_LOST)
{
power_limit = 5000;
}
m_pEngine->Render_DrawRect(&m_rc_energy, TRUE, RGBA_MAKE(126,255,255,50), 0.0f);
int power = Sys_GetTime()-m_msg_holder["use_bubble"];
if (power>power_limit)
{
m_rc_power.top = m_rc_energy.top;
}
else
{
m_rc_power.top = m_rc_power.bottom - power*190/power_limit;
}
if(power>power_limit)
{
int cr = m_pEngine->ValueCycle(198, 255, 0, 100);
m_pEngine->Render_DrawRect(&m_rc_power, TRUE, RGBA_MAKE(cr,cr,150,250), 0.0f);
}
else if(power>power_limit/2)
{
int cr = m_pEngine->ValueCycle(78, 250, 0, 300);
m_pEngine->Render_DrawRect(&m_rc_power, TRUE, RGBA_MAKE(150,cr,70,250), 0.0f);
}
else if(power>power_limit/4)
{
int cr = m_pEngine->ValueCycle(78, 200, 0, 700);
m_pEngine->Render_DrawRect(&m_rc_power, TRUE, RGBA_MAKE(150,cr,0,250), 0.0f);
}
else
{
m_pEngine->Render_DrawRect(&m_rc_power, TRUE, RGBA_MAKE(150,150,0,250), 0.0f);
}
}
// m_pEngine->PreparePaint();
// m_pEngine->DarkenScene(1.9f);
m_pEngine->PreparePaint();
std::list<_EFFECT_SKILL*>::iterator it = m_lst_effect_skill.begin();
while(it!=m_lst_effect_skill.end())
{
float fangle = m_pEngine->ValueCycle(-const_PI_DIV_4/2, const_PI_DIV_4/2, 0, 1000);
float fs = m_pEngine->ValueCycle(0.95f, 1.05f, 0, 800);
#define SSE_T_0 1000
#define SSE_V_0 0.01f
float t_ = SSE_T_0 - m_pEngine->m_dwEngineTime + (*it)->start_time;
if (t_>SSE_T_0)
{
t_ = 0;
}
float fx,fy;
if (t_>0)
{
fx = (*it)->pt_dest.x - (SSE_V_0*t_ + ((*it)->pt_dest.x - (*it)->pt_src.x - SSE_V_0*SSE_T_0)/SSE_T_0/SSE_T_0*t_*t_);
fy = (*it)->pt_dest.y - (SSE_V_0*t_ + ((*it)->pt_dest.y - (*it)->pt_src.y - SSE_V_0*SSE_T_0)/SSE_T_0/SSE_T_0*t_*t_);
}
else
{
fx = (*it)->pt_dest.x;
fy = (*it)->pt_dest.y;
}
(*it)->ani.Update();
(*it)->ani.Draw(fx, fy, 0.0f, fs, fs);
if((*it)->ptr_effect)
{
if (t_<=0)
{
(*it)->ptr_effect->SetSuppressed(TRUE);
}
(*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);
if (t_<=0)
{
delete(*it);
it = m_lst_effect_skill.erase(it);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -