分析Cocos2d-x横版ACT手游源代码 5、3D世界

.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

分析Cocos2d-x横版ACT手游源代码 5、3D世界的相关文章

分析Cocos2d-x横版ACT手游源代码 4、场景

.h文件 #ifndef _CM_GAME_SCENE_H_ #define _CM_GAME_SCENE_H_ #include "../publicdef/PublicDef.h" #include "../gameunit/person/NFEnemy.h" using namespace gui; class CNFGameScene : public cocos2d::CCLayer ,public CMsgReceiver { protected: //

分析Cocos2d-x横版ACT手游源代码 1、登录

我就自己上游戏代码来 因为 这个游戏源代码 注释十分的 都可以看得懂 /************************************************************************/ /* 登录场景 */ /************************************************************************/ class CNFLoginScene : public CCLayer ,public CMsgRecei

分析Cocos2d-x横版ACT手游源代码 1、公共

直接上代码 不说什么 这一款源代码 注释及多 PublicDef.h 公共头文件 #define NF_PLATFORM 1 //当前版本(默认为普通版) //版本列表 #define NF_PLATFORM_NORMAL 1 //normal #define NF_PLATFORM_91 2 //91 playform #define NF_PLATFORM_PP 3 //PP playform #define NF_PLATFORM_UC_ANDROID 4 //UC playform #d

分析Cocos2d-x横版ACT手游源代码 3、人物选择界面

.h文件 #ifndef _NF_ROLE_SELECT_SCENE_HEAD_ #define _NF_ROLE_SELECT_SCENE_HEAD_ #include "../publicdef/PublicDef.h" /************************************************************************/ /*人物选择层 */ /*********************************************

分析Cocos2d-x横版ACT手游源代码 6、创建忍队界面

.h头文件代码 #ifndef _NF_TEAM_CREATE_SCENE_HEAD_ #define _NF_TEAM_CREATE_SCENE_HEAD_ #include "../publicdef/PublicDef.h" /************************************************************************/ /*创建忍队层 */ /******************************************

分析Cocos2d-x横版ACT手游源代码 2、服务器场景

还是一样 直接上代码 源代码 下一篇 上传 大家可以自己看 NFServerChangeLayer.h </pre><pre name="code" class="cpp">/************************************************************************/ /* 服务器切换层 */ /***********************************************

分析Cocos2d-x横版ACT手游源 1、登录

我自己的游戏代码 因为 游戏源 盯着外面的 我们能够能够理解 /************************************************************************/ /* 登录场景 */ /************************************************************************/ class CNFLoginScene : public CCLayer ,public CMsgReceiver

Cocos2d-x三国ACT手游《热血斩将》完整源码下载

目前进度:已经完全编译完成,附带教程文档.感谢作者提供了db文件,已经可以运行. 11.png (57.76 KB, 下载次数: 0) 下载附件 三国ACT手游<热血斩将>完整源码 3 分钟前 上传 编译环境:更新 Cocos2d-x-2.2.1 更新至 2.2.6 VS2012 更新至 VS2013 Windows7 原帖请去论坛找,感谢作者的无私奉献! 为了更好的阅读代码,建议大家采用astyle工具 11.png (19.56 KB, 下载次数: 0) 下载附件 三国ACT手游<热

Unity3D手游-横版ACT游戏完整源码下载

说明: 这不是武林,这不是江湖,没有道不完的恩怨,没有斩不断的情仇,更没有理不清的烦恼,这是剑的世界,一代剑魁闯入未知世界,将会为这个世界展开什么样的蓝图,让你来创造它的未来,剑魁道天下,一剑斗烛龙!!! 游戏开发了三个月,非常值得收藏,至于做什么用途,就看你自己啦!来来来,放大招了!请看附件:) 测试环境: Unity3D 4.3.4 运行效果: 完整源码下载http://www.yxkfw.com/thread-5035-1-1.html