|
想要查看内容赶紧注册登陆吧!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
#include "BulletLayer.h"
#include "GameScene.h"
#include
#include
////////////////////////////////////////////////////////////
CBulletLayer::CBulletLayer()
{
}
CBulletLayer::~CBulletLayer()
{
}
void CBulletLayer::update(float dt)
{
__super::update(dt);
CGameScene *pGameScene = (CGameScene *)parent();
Point ptBullet;
Point ptTBullet;
Point ptFish;
Size szFish;
float sint, cost;
Rect rcScreen(0,0,1280,738);
Nodes::iterator i=child_begin();
for (; i!=child_end(); ++i)
{
CBulletObjectExtend *pBulletObjectExtend = (CBulletObjectExtend *)(*i)->node_extend();
const tagUserInfo * pUserData = NULL;
if(pGameScene->GetClientKernel()!=NULL) pUserData = pGameScene->GetClientKernel()->GetUserInfo(pBulletObjectExtend->wChairID);
ptBullet = (*i)->position();
if (!rcScreen.pt_in_rect(ptBullet))
{
if(pUserData)
{
if((pBulletObjectExtend->nBackCount < 1000)&&(GetBulletCount()<51))
{
if((pBulletObjectExtend->wChairIDwChairID>=0))
{
tagBulletBack tBulletBack;
tBulletBack.ptStart = ptBullet;
if(tBulletBack.ptStart.x_<0) tBulletBack.ptStart.x_ = 0;
else if(tBulletBack.ptStart.x_>1280) tBulletBack.ptStart.x_ = 1280;
if(tBulletBack.ptStart.y_<0) tBulletBack.ptStart.y_ = 0;
else if(tBulletBack.ptStart.y_>738) tBulletBack.ptStart.y_ = 738;
tBulletBack.wChair = pBulletObjectExtend->wChairID;
tBulletBack.nBackCount = pBulletObjectExtend->nBackCount + 1;
tBulletBack.fRotation = pBulletObjectExtend->fRotation;
tBulletBack.dwMulRate = pBulletObjectExtend->dwMulRate;
tBulletBack.wType = pBulletObjectExtend->CannonType;
m_BulletBackList.push_back(tBulletBack);
}
}
}
m_NodeDelete.push_back((*i));
continue;
}
Nodes::iterator j=pGameScene->m_layFishObject->child_begin();
for (; j!=pGameScene->m_layFishObject->child_end(); ++j)
{
CFishObjectExtend *pFishObjectExtend = (CFishObjectExtend *)(*j)->node_extend();
if (pFishObjectExtend->wID == INVALID_WORD)
continue;
ptFish = (*j)->position();
szFish = pFishObjectExtend->GetFishObjectSize();
cost = std::cosf((*j)->rotation());
sint = std::sinf((*j)->rotation());
ptTBullet.x_ = (ptBullet.x_-ptFish.x_)*cost + (ptBullet.y_-ptFish.y_)*sint;
ptTBullet.y_ = -(ptBullet.x_-ptFish.x_)*sint + (ptBullet.y_-ptFish.y_)*cost;
if (CFishObjectExtend::ComputeCollision(szFish.width_, szFish.height_, 10, ptTBullet.x_, ptTBullet.y_ ))
{
pGameScene->m_layNetObject->NetFire(ptBullet, pBulletObjectExtend->wChairID, pBulletObjectExtend->CannonType,pBulletObjectExtend->dwMulRate);
m_NodeDelete.push_back((*i));
break;
}
}
}
std::vector::iterator k=m_NodeDelete.begin();
for (; k!=m_NodeDelete.end(); ++k)
{
remove_child((*k));
delete (*k)->node_extend();
delete (*k);
}
m_NodeDelete.clear();
if(m_BulletBackList.size() > 0)
{
std::vector::iterator it;
for(it=m_BulletBackList.begin();it!=m_BulletBackList.end();it++)
{
float fRotation = (it->ptStart.x_ >= 1280) ? -it->fRotation : (it->ptStart.y_ <= -it-="">fRotation + M_PI : (it->ptStart.y_ >= 738) ? -it->fRotation + M_PI : -it->fRotation;
BulletFireBack(it->ptStart, fRotation ,it->wChair ,(CGameCore::enCannonType) it->wType, it->nBackCount, it->dwMulRate);
}
}
m_BulletBackList.clear();
}
void CBulletLayer::draw()
{
__super::draw();
}
bool CBulletLayer::BulletFire(const Point &ptStart, float rotation, WORD wChairID, CGameCore::enCannonType CannonType, DWORD dwMulRate)
{
if(GetBulletCount()>51) return true;
CBulletObjectExtend *BulletObjectExtend = new CBulletObjectExtend;
BulletObjectExtend->fRotation = rotation;
BulletObjectExtend->wChairID = wChairID;
BulletObjectExtend->CannonType = CannonType;
BulletObjectExtend->dwMulRate = dwMulRate;
int nFirst=0;
if (CannonType > CGameCore::CannonType_5)
{
nFirst = 1;
}
Size szScale;
switch(CannonType)
{
case CGameCore::CannonType_0: { szScale.width_=0.5; szScale.height_=0.5; break; }
case CGameCore::CannonType_1: { szScale.width_=0.6; szScale.height_=0.6; break; }
case CGameCore::CannonType_2: { szScale.width_=0.7; szScale.height_=0.7; break; }
case CGameCore::CannonType_3: { szScale.width_=0.8; szScale.height_=0.8; break; }
case CGameCore::CannonType_4: { szScale.width_=0.9; szScale.height_=0.9; break; }
case CGameCore::CannonType_5: { szScale.width_=0.9; szScale.height_=0.9; break; }
case CGameCore::CannonType_6: { szScale.width_=1.0; szScale.height_=1.0; break; }
}
std:stringstream ostr;
ostr << "shot_" <<nFirst << "_"<< (int)wChairID ;
Sprite *sprBullet = new Sprite(Root::instance()->imageset_manager()->imageset(ostr.str())->image("0"));
sprBullet->set_node_extend(BulletObjectExtend);
Point pt (ptStart.x_+56*std::cos(rotation-M_PI_2), ptStart.y_+56*std::sin(rotation-M_PI_2));
sprBullet->set_position(pt);
sprBullet->set_rotation(rotation);
sprBullet->set_scale(szScale);
add_child(sprBullet);
Action *actBullet = new Action_Move_By(3, Point(2000*std::cos(rotation-M_PI_2),2000*std::sin(rotation-M_PI_2)));
sprBullet->run_action(actBullet);
Animation *aniBullet = Root::instance()->animation_manager()->animation(ostr.str());
sprBullet->run_action(new Action_Repeat_Forever (new Action_Animation(0.06,aniBullet,false)));
// CGameScene *pGameScene = (CGameScene *)parent();
// if (wChairID == pGameScene->GetMeChairID())
// {
// CMD_C_Fire Fire;
//Fire.cbIsBack = FALSE;
// Fire.fRote = rotation;
//Fire.dwMulRate = dwMulRate;
//Fire.xStart = 0;
//Fire.yStart = 0;
// pGameScene->GetClientKernel()->SendSocketData(MDM_GF_GAME, SUB_C_FIRE, &Fire, sizeof(CMD_C_Fire));
// }
try
{
Sound_Instance *pSound = Root::instance()->sound_manager()->sound_instance(nFirst+5);
pSound->play(false, true);
}
catch(...)
{
}
return true;
}
bool CBulletLayer::BulletFireBack(const Point &ptStart, float rotation, WORD wChairID, CGameCore::enCannonType CannonType,int nBackCount, DWORD dwMulRate)
{
if(GetBulletCount()>51) return true;
CBulletObjectExtend *BulletObjectExtend = new CBulletObjectExtend;
BulletObjectExtend->nBackCount = nBackCount;
BulletObjectExtend->fRotation = rotation;
BulletObjectExtend->wChairID = wChairID;
BulletObjectExtend->CannonType = CannonType;
BulletObjectExtend->dwMulRate = dwMulRate;
int nFirst=0;
if (CannonType > CGameCore::CannonType_5)
{
nFirst = 1;
}
Size szScale;
switch(CannonType)
{
case CGameCore::CannonType_0: { szScale.width_=0.5; szScale.height_=0.5; break; }
case CGameCore::CannonType_1: { szScale.width_=0.6; szScale.height_=0.6; break; }
case CGameCore::CannonType_2: { szScale.width_=0.7; szScale.height_=0.7; break; }
case CGameCore::CannonType_3: { szScale.width_=0.8; szScale.height_=0.8; break; }
case CGameCore::CannonType_4: { szScale.width_=0.9; szScale.height_=0.9; break; }
case CGameCore::CannonType_5: { szScale.width_=0.9; szScale.height_=0.9; break; }
case CGameCore::CannonType_6: { szScale.width_=1.0; szScale.height_=1.0; break; }
}
std:stringstream ostr;
ostr << "shot_" <<nFirst << "_"<< (int)wChairID ;
Sprite *sprBullet = new Sprite(Root::instance()->imageset_manager()->imageset(ostr.str())->image("0"));
sprBullet->set_node_extend(BulletObjectExtend);
Point pt (ptStart.x_+56*std::cos(rotation-M_PI_2), ptStart.y_+56*std::sin(rotation-M_PI_2));
sprBullet->set_position(pt);
sprBullet->set_rotation(rotation);
sprBullet->set_scale(szScale);
add_child(sprBullet);
Action *actBullet = new Action_Move_By(3, Point(2000*std::cos(rotation-M_PI_2),2000*std::sin(rotation-M_PI_2)));
sprBullet->run_action(actBullet);
Animation *aniBullet = Root::instance()->animation_manager()->animation(ostr.str());
sprBullet->run_action(new Action_Repeat_Forever (new Action_Animation(0.06,aniBullet,false)));
//CGameScene *pGameScene = (CGameScene *)parent();
//if (wChairID == pGameScene->GetMeChairID())
//{
// CMD_C_Fire Fire;
// Fire.cbIsBack = TRUE;
// Fire.fRote = rotation;
// Fire.dwMulRate = dwMulRate;
// Fire.xStart = ptStart.x_;
// Fire.yStart = ptStart.y_;
// pGameScene->GetClientKernel()->SendSocketData(MDM_GF_GAME, SUB_C_FIRE, &Fire, sizeof(CMD_C_Fire));
//}
return true;
}
int CBulletLayer::GetBulletCount()
{
int nCount = 0;
Nodes::iterator i=child_begin();
for (; i!=child_end(); ++i)
{
CBulletObjectExtend *pBulletObjectExtend = (CBulletObjectExtend *)(*i)->node_extend();
Point ptBullet = (*i)->position();
Rect rcScreen(0,0,1280,738);
if (rcScreen.pt_in_rect(ptBullet))
{
nCount++;
}
}
return nCount;
}
void CBulletLayer::ClearAllBullets()
{
Nodes::iterator i=child_begin();
for (; i!=child_end(); ++i)
{
remove_child((*i));
delete (*i)->node_extend();
delete (*i);
}
}
////////////////////////////////////////////////////////////
|
|