.h文件
#ifndef _NF_3D_WORLD_LAYER_HEAD_ #define _NF_3D_WORLD_LAYER_HEAD_ #include "../publicdef/PublicDef.h" #include "../gameunit/NFWorld3D.h" #include "../datamanager/NFEnemyWave.h" class CNF3DWorldLayer : public CNFWorld3DLayer ,public CMsgReceiver,public CMsgSender { public: //标签 enum { enTagMidTMXMap = 10000, enTagTMXMap1, enTagTMXMap2, enTagTMXMap3, }; CCArray * m_pArticleArray; //物体数组 CCArray *m_pFriendArray; //友方 CCArray *m_pEnemyArray; //敌方 int m_nStageID; //关卡ID int m_nRoleID; //角色ID CNFEnemyWave * m_pEnemyWave; //敌人波次 public: static CNF3DWorldLayer * CreateLayer(int nStageID,int nRoleID); //更新函数 void update(float delta); //点击NPC。返回NPC的ID, 0为没有点击到NPC int ClickNPC(CCTouch *pTouch); //接收函数 virtual void RecMsg(int enMsg,void* pData,int nSize); protected: virtual bool InitLayer(int nStageID,int nRoleID); //消息处理:移除敌人 bool OnSubMsgEnemyRemove(void *pInfo,int nSize); //消息处理:移除主角 bool OnSubMsgProtagonistRemove(void *pInfo,int nSize); //消息处理:敌人普通攻击 bool OnSubMsgEnemyCommonAttack(void *pInfo,int nSize); //消息处理:技能 bool OnSubMsgProtagonistSkill(void *pInfo,int nSize); //消息处理:切换场景 bool OnSubMsgTransfer(void *pInfo,int nSize); //消息处理:创建敌人 bool OnSubMsgCreateEnemy(void *pInfo,int nSize); //消息处理:游戏胜利 bool OnSubMsgGameWin(void *pInfo,int nSize); void onExit(); }; #endif
.cpp文件
#include "NF3DWorldLayer.h" #include "../tiledmap/NFTMXTiledMap.h" #include "../gameunit/person/NFProtagonist.h" #include "../gameunit/skill/NFCommonAttack.h" #include "../gameunit/person/NFEnemy.h" #include "../gameunit/article/NFBox.h" #include "../gameunit/article/NFNPC.h" #include "../gameunit/article/NFTransferDoor.h" #include "../datamanager/NFDataManager.h" #include "gamescene/NFGameScene.h" #include "../ui/NFTownScene.h" #define _TMX_START_X_<span style="white-space:pre"> </span>-30<span style="white-space:pre"> </span>//景深地图初始x轴坐标 CNF3DWorldLayer* CNF3DWorldLayer::CreateLayer(int nStageID,int nRoleID) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>CNF3DWorldLayer* pLayer = new CNF3DWorldLayer(); <span style="white-space:pre"> </span>if (pLayer!=NULL && pLayer->InitLayer(nStageID,nRoleID)==true) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>pLayer->autorelease(); <span style="white-space:pre"> </span>return pLayer; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>delete pLayer; <span style="white-space:pre"> </span>pLayer = NULL; <span style="white-space:pre"> </span>return NULL; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNF3DWorldLayer::CreateLayer Error!"); <span style="white-space:pre"> </span>return NULL; } bool CNF3DWorldLayer::InitLayer(int nStageID,int nRoleID) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//读取关卡信息 <span style="white-space:pre"> </span>tagStageStaticInfo StageInfo; <span style="white-space:pre"> </span>CNFStaticDataManager::SharedData()->GetStageStaticInfo(nStageID,StageInfo); <span style="white-space:pre"> </span>if (StageInfo.fRate < 0) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>CCLog("Fun 3D WorldLayer Create Error!"); <span style="white-space:pre"> </span>return false; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>m_nStageID = nStageID; <span style="white-space:pre"> </span>m_nRoleID = nRoleID; <span style="white-space:pre"> </span>tagSize3D StageSize3DInfo; <span style="white-space:pre"> </span>StageSize3DInfo.fHeight=StageInfo.fHeight; <span style="white-space:pre"> </span>StageSize3DInfo.fLength=StageInfo.fLength; <span style="white-space:pre"> </span>StageSize3DInfo.fWidth=StageInfo.fWidth; <span style="white-space:pre"> </span>//初始化父类 <span style="white-space:pre"> </span>CC_BREAK_IF(CNFWorld3DLayer::init(StageInfo.fRate,StageSize3DInfo)==false); <span style="white-space:pre"> </span>m_pArticleArray = CCArray::create(); <span style="white-space:pre"> </span>m_pArticleArray->retain(); <span style="white-space:pre"> </span>m_pFriendArray = CCArray::create(); <span style="white-space:pre"> </span>m_pFriendArray->retain(); <span style="white-space:pre"> </span>m_pEnemyArray = CCArray::create(); <span style="white-space:pre"> </span>m_pEnemyArray->retain(); <span style="white-space:pre"> </span>//CNFBox* pBox = CNFBox::CreateBox(1); <span style="white-space:pre"> </span>//pBox->SetMsg(this); <span style="white-space:pre"> </span>//pBox->setPosition3D(400,400); <span style="white-space:pre"> </span>//addChild(pBox,enZOrderMid); <span style="white-space:pre"> </span>//m_pArticleArray->addObject(pBox); <span style="white-space:pre"> </span>tagPosition3D ptPos3D; <span style="white-space:pre"> </span>//创建角色 <span style="white-space:pre"> </span>CNFProtagonist* pProtagonist = CNFProtagonist::Create(m_nRoleID,m_pFriendArray,m_pEnemyArray); <span style="white-space:pre"> </span>ptPos3D.fX = StageInfo.fProtagonistX; <span style="white-space:pre"> </span>ptPos3D.fY = StageInfo.fProtagonistY; <span style="white-space:pre"> </span>ptPos3D.fZ = 0; <span style="white-space:pre"> </span>pProtagonist->SetMsg(this); <span style="white-space:pre"> </span>pProtagonist->setPosition3D(ptPos3D); <span style="white-space:pre"> </span>pProtagonist->SetArticleArray(m_pArticleArray); <span style="white-space:pre"> </span>addChild(pProtagonist,enZOrderMid,enTagProtagonist); <span style="white-space:pre"> </span>m_pFriendArray->addObject(pProtagonist); <span style="white-space:pre"> </span>SetProtagonist(pProtagonist); <span style="white-space:pre"> </span>//创建NPC <span style="white-space:pre"> </span>for (CNFNPCJsonInfoVec::iterator it = StageInfo.NPCJsonInfoVec.begin();it != StageInfo.NPCJsonInfoVec.end();it++) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>CNFNPC* pNPC1 = CNFNPC::Create(it->nNPCID,it->NPCStaticInfo.strArmatureName.c_str(),it->NPCStaticInfo.fLength,it->NPCStaticInfo.fWidth,it->NPCStaticInfo.fHeight); <span style="white-space:pre"> </span>pNPC1->SetMsg(this); <span style="white-space:pre"> </span>ptPos3D.fX = it->fPosX; <span style="white-space:pre"> </span>ptPos3D.fY = it->fPosY; <span style="white-space:pre"> </span>ptPos3D.fZ = it->fPosZ; <span style="white-space:pre"> </span>pNPC1->setPosition3D(ptPos3D); <span style="white-space:pre"> </span>addChild(pNPC1,enZOrderMid); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>//创建门 <span style="white-space:pre"> </span>for (CNFDoorJsonInfoVec::iterator it = StageInfo.DoorJsonInfoVec.begin();it != StageInfo.DoorJsonInfoVec.end();it++) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>CNFTransferDoor* pTransferDoor = CNFTransferDoor::Create(it->DoorStaticInfo.nRelaceStageID,pProtagonist,it->DoorStaticInfo.strArmatureName.c_str(),it->DoorStaticInfo.fLength,it->DoorStaticInfo.fWidth,it->DoorStaticInfo.fHeight); <span style="white-space:pre"> </span>pTransferDoor->SetMsg(this); <span style="white-space:pre"> </span>ptPos3D.fX = it->fPosX; <span style="white-space:pre"> </span>ptPos3D.fY = it->fPosY; <span style="white-space:pre"> </span>ptPos3D.fZ = it->fPosZ; <span style="white-space:pre"> </span>pTransferDoor->setPosition3D(ptPos3D); <span style="white-space:pre"> </span>addChild(pTransferDoor,enZOrderMid); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>//若为副本 <span style="white-space:pre"> </span>if (nStageID >= _NF_TOWN_OR_BATTLE_ID_ && nStageID <_NF_TOWN_FB_ID_) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//创建敌人波次 <span style="white-space:pre"> </span>m_pEnemyWave = CNFEnemyWave::CreateEnemyWave(nStageID,m_pEnemyArray); <span style="white-space:pre"> </span>CC_BREAK_IF(m_pEnemyWave==NULL); <span style="white-space:pre"> </span>m_pEnemyWave->SetMsg(this); // <span style="white-space:pre"> </span>CNFProtagonist* pProtagonist2 = CNFProtagonist::Create(2,m_pFriendArray,m_pEnemyArray); // <span style="white-space:pre"> </span>ptPos3D.fX = 700; // <span style="white-space:pre"> </span>ptPos3D.fY = 500; // <span style="white-space:pre"> </span>ptPos3D.fZ = 0; // <span style="white-space:pre"> </span>pProtagonist2->SetMsg(this); // <span style="white-space:pre"> </span>pProtagonist2->setPosition3D(ptPos3D); // <span style="white-space:pre"> </span>pProtagonist2->SetArticleArray(m_pArticleArray); // <span style="white-space:pre"> </span>pProtagonist2->SetAutoMode(true); // <span style="white-space:pre"> </span>addChild(pProtagonist2,enZOrderMid); // <span style="white-space:pre"> </span>m_pFriendArray->addObject(pProtagonist2); // // <span style="white-space:pre"> </span>CNFProtagonist* pProtagonist3 = CNFProtagonist::Create(1,m_pEnemyArray,m_pFriendArray); // <span style="white-space:pre"> </span>ptPos3D.fX = 700; // <span style="white-space:pre"> </span>ptPos3D.fY = 100; // <span style="white-space:pre"> </span>ptPos3D.fZ = 0; // <span style="white-space:pre"> </span>pProtagonist3->SetMsg(this); // <span style="white-space:pre"> </span>pProtagonist3->setPosition3D(ptPos3D); // <span style="white-space:pre"> </span>pProtagonist3->SetArticleArray(m_pArticleArray); // <span style="white-space:pre"> </span>pProtagonist3->SetAutoMode(true); // <span style="white-space:pre"> </span>addChild(pProtagonist3,enZOrderMid); // <span style="white-space:pre"> </span>m_pEnemyArray->addObject(pProtagonist3); // //<span style="white-space:pre"> </span>// //<span style="white-space:pre"> </span>CNFEnemy* pEnemy = CNFEnemy::CreateEnemy(pProtagonist); //<span style="white-space:pre"> </span>pEnemy->SetMsg(this); //<span style="white-space:pre"> </span>ptPos3D.fX = 700; //<span style="white-space:pre"> </span>ptPos3D.fY = 20; //<span style="white-space:pre"> </span>ptPos3D.fZ = 0; //<span style="white-space:pre"> </span>pEnemy->setPosition3D(ptPos3D); //<span style="white-space:pre"> </span>addChild(pEnemy,enZOrderMid); //<span style="white-space:pre"> </span>pEnemy->SetArticleArray(m_pArticleArray); //<span style="white-space:pre"> </span>m_pEnemyArray->addObject(pEnemy); // // <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>//tiledmap <span style="white-space:pre"> </span>CNFMidTMXMap* pGameMap = CNFMidTMXMap::CreateGameMap(StageInfo.strTMXWorldName.c_str(),this); <span style="white-space:pre"> </span>CC_BREAK_IF(pGameMap==NULL); <span style="white-space:pre"> </span>pGameMap->setPosition(ccp(_TMX_START_X_,0)); <span style="white-space:pre"> </span>addChild(pGameMap,-enTagMidTMXMap,enTagMidTMXMap); <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>//创建景深地图 <span style="white-space:pre"> </span>int i = enTagTMXMap1; <span style="white-space:pre"> </span>for (CNFTmxStaticInfoMap::iterator it = StageInfo.TmxStaticInfoMap.begin();it != StageInfo.TmxStaticInfoMap.end();it++) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>CMGameMapLayer* pGameMap = CMGameMapLayer::CreateGameMap(it->second.strTmxName.c_str()); <span style="white-space:pre"> </span>CC_BREAK_IF(pGameMap==NULL); <span style="white-space:pre"> </span>pGameMap->setAnchorPoint(ccp(0,0)); <span style="white-space:pre"> </span>pGameMap->setPosition(ccp(it->second.fStartPosX,it->second.fStartPosY)); <span style="white-space:pre"> </span>addChild(pGameMap,-i,i); <span style="white-space:pre"> </span>if (i==enTagTMXMap1)<span style="white-space:pre"> </span>pGameMap->SetSpeedMultipleX(0.9f); <span style="white-space:pre"> </span>if (i==enTagTMXMap2)<span style="white-space:pre"> </span>pGameMap->SetSpeedMultipleX(0.1f); <span style="white-space:pre"> </span>if (i==enTagTMXMap3)<span style="white-space:pre"> </span>pGameMap->SetSpeedMultipleX(1.0f); <span style="white-space:pre"> </span>i++; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>return true; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNF3DWorldLayer::init Error!"); <span style="white-space:pre"> </span>return false; } void CNF3DWorldLayer::update(float delta) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>CCObject *pItem = NULL; <span style="white-space:pre"> </span>CCARRAY_FOREACH(getChildren(),pItem) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>CNFBasicUnit *pNodeItem = dynamic_cast<CNFBasicUnit*>(pItem); <span style="white-space:pre"> </span>if(pNodeItem!=NULL) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//调整显示层级 <span style="white-space:pre"> </span>int nZOrder = enZOrderMid - pNodeItem->getPositionY(); <span style="white-space:pre"> </span>pNodeItem->setZOrder(nZOrder); <span style="white-space:pre"> </span>pNodeItem->CallPerFrame(delta); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>//遍历敌人波次 <span style="white-space:pre"> </span>if (m_nStageID >= _NF_TOWN_OR_BATTLE_ID_ && m_nStageID <_NF_TOWN_FB_ID_) <span style="white-space:pre"> </span>m_pEnemyWave->update(); <span style="white-space:pre"> </span>//景深地图同步位置 <span style="white-space:pre"> </span>for (int i=enTagTMXMap1;i<=enTagTMXMap3;i++) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>CMGameMapLayer* pGameMap = dynamic_cast<CMGameMapLayer *>(getChildByTag(i)); <span style="white-space:pre"> </span>if (pGameMap!=NULL) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//若存在缩放 <span style="white-space:pre"> </span>if (getScale() != 1) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>//若不存在缩放 <span style="white-space:pre"> </span>else <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>pGameMap->setPositionX( getPositionX()*(pGameMap->GetSpeedMultipleX()-1) + _TMX_START_X_ ); <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>CNFProtagonist* pProtagonist = dynamic_cast<CNFProtagonist*>(getChildByTag(enTagProtagonist)); <span style="white-space:pre"> </span>if(pProtagonist==NULL){ <span style="white-space:pre"> </span>SetProtagonist(NULL); <span style="white-space:pre"> </span>SendMsg(enMsgCreateGameOverLayer,NULL,sizeof(NULL)); <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>//CCLog("=========%f====%f",getPositionX(),getPositionY()); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>return; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNF3DWorldLayer::update Error!"); } int CNF3DWorldLayer::ClickNPC( CCTouch *pTouch ) { <span style="white-space:pre"> </span>CCObject *pItem = NULL; <span style="white-space:pre"> </span>CCARRAY_FOREACH(getChildren(),pItem) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>CNFNPC *pNodeItem = dynamic_cast<CNFNPC*>(pItem); <span style="white-space:pre"> </span>if(pNodeItem!=NULL) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>tagPosition3D wzNPC = pNodeItem->GetCurrentCube()->ptPos3D; <span style="white-space:pre"> </span>tagSize3D szNPC = pNodeItem->GetCurrentCube()->szCube; <span style="white-space:pre"> </span>CCPoint NPC2DPoint = ccp(wzNPC.fX + getPositionX() - 50,wzNPC.fY*pNodeItem->GetLTRate() + wzNPC.fZ); <span style="white-space:pre"> </span>CCRect NPC2DRect = CCRectMake(NPC2DPoint.x,NPC2DPoint.y,szNPC.fLength,szNPC.fHeight); <span style="white-space:pre"> </span>if(NPC2DPoint.x>0&&NPC2DRect.containsPoint(pTouch->getLocation())){ <span style="white-space:pre"> </span>//CCLog("%d==================%f",pNodeItem->GetID(),wzNPC.fX); <span style="white-space:pre"> </span>CNFProtagonist* pRole = dynamic_cast<CNFProtagonist*>(getChildByTag(enTagProtagonist)); <span style="white-space:pre"> </span>if(pRole!=NULL){ <span style="white-space:pre"> </span>pRole->OnCtrlMoveToPonit(ccp(pNodeItem->GetCurrentCube()->ptPos3D.fX,pNodeItem->GetCurrentCube()->ptPos3D.fY)); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>return 0; } void CNF3DWorldLayer::RecMsg( int enMsg,void* pData,int nSize ) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>switch(enMsg) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>case enMsg_Hit_Enemy: <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//发消息,得到被击中的敌人是谁 <span style="white-space:pre"> </span>SendMsg(enMsg_Hit_Enemy,pData,nSize); <span style="white-space:pre"> </span>}break; <span style="white-space:pre"> </span>case enMsg_RemoveEnemy:<span style="white-space:pre"> </span> <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>SendMsg(enMsg_RemoveEnemy,NULL,0); <span style="white-space:pre"> </span>OnSubMsgEnemyRemove( pData,nSize ); <span style="white-space:pre"> </span>}break; <span style="white-space:pre"> </span>case enMsg_RemoveProtagonist:<span style="white-space:pre"> </span> <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>OnSubMsgProtagonistRemove( pData,nSize ); <span style="white-space:pre"> </span>}break; <span style="white-space:pre"> </span>case enMsgEnemyCommonAttack:<span style="white-space:pre"> </span> <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>OnSubMsgEnemyCommonAttack( pData,nSize ); <span style="white-space:pre"> </span>}break; <span style="white-space:pre"> </span>case enMsgProtagonistSkill:<span style="white-space:pre"> </span>//消息处理:技能 <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>OnSubMsgProtagonistSkill( pData,nSize ); <span style="white-space:pre"> </span>}break; <span style="white-space:pre"> </span>case enMsgProtagonistTransfer:<span style="white-space:pre"> </span>//消息处理:传送门 <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>OnSubMsgTransfer( pData,nSize ); <span style="white-space:pre"> </span>}break; <span style="white-space:pre"> </span>//创建敌人 <span style="white-space:pre"> </span>case enMsgCreateEnemy: <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>OnSubMsgCreateEnemy(pData,nSize); <span style="white-space:pre"> </span>}break; <span style="white-space:pre"> </span>//游戏结束 <span style="white-space:pre"> </span>case enMsgGameWin: <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>OnSubMsgGameWin(pData,nSize); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>return ; <span style="white-space:pre"> </span>} while (false); } void CNF3DWorldLayer::onExit() { <span style="white-space:pre"> </span>m_pArticleArray->release(); <span style="white-space:pre"> </span>m_pFriendArray->release(); <span style="white-space:pre"> </span>m_pEnemyArray->release(); <span style="white-space:pre"> </span>CNFWorld3DLayer::onExit(); } bool CNF3DWorldLayer::OnSubMsgEnemyRemove( void *pInfo,int nSize ) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//tagPosition3D ptPos3D; <span style="white-space:pre"> </span>tagRemovePerson *pCmd = (tagRemovePerson*)pInfo; <span style="white-space:pre"> </span>if(pCmd->pArrayTarget!=NULL){ <span style="white-space:pre"> </span>pCmd->pArrayTarget->removeObject(pCmd->pPerson); <span style="white-space:pre"> </span>}else{ <span style="white-space:pre"> </span>m_pEnemyArray->removeObject(pCmd->pPerson); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>this->removeChild(pCmd->pPerson); <span style="white-space:pre"> </span>return true; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNF3DWorldLayer::OnSubMsgEnemyRemove Error!"); <span style="white-space:pre"> </span>return false; } bool CNF3DWorldLayer::OnSubMsgProtagonistRemove( void *pInfo,int nSize ) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>tagRemovePerson *pCmd = (tagRemovePerson*)pInfo; <span style="white-space:pre"> </span>if(pCmd->pArrayTarget!=NULL){ <span style="white-space:pre"> </span>pCmd->pArrayTarget->removeObject(pCmd->pPerson); <span style="white-space:pre"> </span>}else{ <span style="white-space:pre"> </span>m_pFriendArray->removeObject(pCmd->pPerson); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>this->removeChild(pCmd->pPerson); <span style="white-space:pre"> </span>return true; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNF3DWorldLayer::OnSubMsgProtagonistRemove Error!"); <span style="white-space:pre"> </span>return false; } bool CNF3DWorldLayer::OnSubMsgEnemyCommonAttack( void *pInfo,int nSize ) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//return true; <span style="white-space:pre"> </span>tagPosition3D ptPos3D; <span style="white-space:pre"> </span>tagCommonAttack *pCmd = (tagCommonAttack*)pInfo; <span style="white-space:pre"> </span>CNFCommonAttack* pAttack = CNFCommonAttack::CreateCommonAttack(pCmd,m_pFriendArray); <span style="white-space:pre"> </span>if(pAttack!=NULL){ <span style="white-space:pre"> </span>ptPos3D.fX = pCmd->pReleaser->GetCurrentCube()->ptPos3D.fX + pCmd->fOldX; <span style="white-space:pre"> </span>ptPos3D.fY = pCmd->pReleaser->GetCurrentCube()->ptPos3D.fY + pCmd->fOldY; <span style="white-space:pre"> </span>ptPos3D.fZ = pCmd->pReleaser->GetCurrentCube()->ptPos3D.fZ + pCmd->fOldZ; <span style="white-space:pre"> </span>pAttack->setPosition3D(ptPos3D); <span style="white-space:pre"> </span>pAttack->SetGround(pCmd->pReleaser->GetGround()); <span style="white-space:pre"> </span>pAttack->SetMsg(this); <span style="white-space:pre"> </span>this->addChild(pAttack,pCmd->pReleaser->getZOrder()); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>return true; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNF3DWorldLayer::OnSubMsgEnemyCommonAttack Error!"); <span style="white-space:pre"> </span>return false; } bool CNF3DWorldLayer::OnSubMsgProtagonistSkill( void *pInfo,int nSize ) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//return true; <span style="white-space:pre"> </span>tagPosition3D ptPos3D; <span style="white-space:pre"> </span>tagCommonAttack *pCmd = (tagCommonAttack*)pInfo; <span style="white-space:pre"> </span>CNFCommonAttack* pAttack = CNFCommonAttack::CreateCommonAttack(pCmd,pCmd->pArrayTarget); <span style="white-space:pre"> </span>if(pAttack!=NULL){ <span style="white-space:pre"> </span>ptPos3D.fX = pCmd->pReleaser->GetCurrentCube()->ptPos3D.fX + pCmd->fOldX; <span style="white-space:pre"> </span>ptPos3D.fY = pCmd->pReleaser->GetCurrentCube()->ptPos3D.fY + pCmd->fOldY; <span style="white-space:pre"> </span>ptPos3D.fZ = pCmd->pReleaser->GetCurrentCube()->ptPos3D.fZ + pCmd->fOldZ; <span style="white-space:pre"> </span>pAttack->setPosition3D(ptPos3D); <span style="white-space:pre"> </span>pAttack->SetGround(pCmd->pReleaser->GetGround()); <span style="white-space:pre"> </span>pAttack->SetMsg(this); <span style="white-space:pre"> </span>this->addChild(pAttack,pCmd->pReleaser->getZOrder()); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>return true; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNF3DWorldLayer::OnSubMsgProtagonistSkill Error!"); <span style="white-space:pre"> </span>return false; } bool CNF3DWorldLayer::OnSubMsgTransfer( void *pInfo,int nSize ) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>tagTransferDoor *pCmd = (tagTransferDoor*)pInfo; <span style="white-space:pre"> </span>CC_BREAK_IF(pCmd->nID<=0); <span style="white-space:pre"> </span>if(pCmd->nID>_NF_TOWN_OR_BATTLE_ID_ && pCmd->nID <_NF_TOWN_FB_ID_){ <span style="white-space:pre"> </span>//跳转到副本 <span style="white-space:pre"> </span>CCScene * pScene = CNFGameScene::CreateGameScene(pCmd->nID,m_nRoleID); <span style="white-space:pre"> </span>CC_BREAK_IF(pScene==NULL); <span style="white-space:pre"> </span>CCDirector::sharedDirector()->replaceScene(/*CCTransitionFade::create(1.f,pScene)*/pScene); <span style="white-space:pre"> </span>}else if(pCmd->nID>0 && pCmd->nID <_NF_TOWN_OR_BATTLE_ID_) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//跳转到城镇 <span style="white-space:pre"> </span>CCScene * pScene = CNFTownScene::CreateTownScene(pCmd->nID,m_nRoleID); <span style="white-space:pre"> </span>CC_BREAK_IF(pScene==NULL); <span style="white-space:pre"> </span>CCDirector::sharedDirector()->replaceScene(/*CCTransitionFade::create(1.f,pScene)*/pScene); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>else <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>SendMsg(enMsgCreateFbSelectLayer,&pCmd->nID,sizeof(pCmd->nID)); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>return true; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNF3DWorldLayer::OnSubMsgTransferSkill Error!"); <span style="white-space:pre"> </span>return false; } //消息处理:创建敌人 bool CNF3DWorldLayer::OnSubMsgCreateEnemy( void *pInfo,int nSize ) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>Cmd_CreateEnemyInfo *pCmd = (Cmd_CreateEnemyInfo *)pInfo; <span style="white-space:pre"> </span>CNFProtagonist* pProtagonist = dynamic_cast<CNFProtagonist*>(getChildByTag(enTagProtagonist)); <span style="white-space:pre"> </span>if(pProtagonist!=NULL){ <span style="white-space:pre"> </span>CNFEnemy* pEnemy = CNFEnemy::CreateEnemy(pCmd->nEnemyID,pCmd->nEnemyLevel,m_pEnemyArray,m_pFriendArray); <span style="white-space:pre"> </span>CC_BREAK_IF(pEnemy==NULL); <span style="white-space:pre"> </span>pEnemy->SetMsg(this); <span style="white-space:pre"> </span>int nTempL = Get3DWorldSize()->fLength; <span style="white-space:pre"> </span>int nTempW = Get3DWorldSize()->fWidth; <span style="white-space:pre"> </span>tagPosition3D ptPos3D; <span style="white-space:pre"> </span>ptPos3D.fX = pCmd->fPosX; <span style="white-space:pre"> </span>ptPos3D.fY = pCmd->fPosY; <span style="white-space:pre"> </span>ptPos3D.fZ = 0; <span style="white-space:pre"> </span>pEnemy->setPosition3D(ptPos3D); <span style="white-space:pre"> </span>pEnemy->SetArticleArray(m_pArticleArray); <span style="white-space:pre"> </span>addChild(pEnemy,enZOrderMid); <span style="white-space:pre"> </span>m_pEnemyArray->addObject(pEnemy); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>return true; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNF3DWorldLayer::OnSubMsgCreateEnemy Error!"); <span style="white-space:pre"> </span>return false; } //消息处理:游戏结束 bool CNF3DWorldLayer::OnSubMsgGameWin( void *pInfo,int nSize ) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>SendMsg(enMsgCreateGameWinLayer,NULL,sizeof(NULL)); <span style="white-space:pre"> </span>return true; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNF3DWorldLayer::OnSubMsgGameWin Error!"); <span style="white-space:pre"> </span>return false; } 个人博客 www.sundaboke.com
时间: 2024-11-06 23:26:45