Ejemplo n.º 1
0
//----------------------------------------------------------------------------------------
//			others function means other players'
//----------------------------------------------------------------------------------------
void BaseLevelBuilder::addOtherPlayer(unsigned int uid, const char* userName,unsigned int type, cocos2d::CCPoint pt, unsigned int orient, unsigned int battleSide)
{
	std::map<uint32_t, OthersPlayerInfo>::iterator itor = m_level->m_othersPlayerInfo.find(uid);
	if (itor == m_level->m_othersPlayerInfo.end())
	{
		//
		OthersPlayerInfo playerInfo;
		playerInfo.seer = NULL;
		playerInfo.pet = NULL;
#if _DEBUG
		playerInfo.name = userName;
#endif
		//add seer
		ASSERT(m_level->m_levelDataReference->mapFilePointer != NULL, "map file is empty");
		SpriteSeer* seer = LevelObjectCreator::sCreateSeer(uid,userName,
			type, 
			false);

		if(NULL == seer)
		{
			return;
		}

		

		seer->SetID(uid);
		seer->setTag(MAP_TAG_OTHER_SEER);
		seer->setPosition(pt);
		seer->SetBattleSide(battleSide);

		if (m_level->m_pObjectsLayer)
		{
			m_level->m_pObjectsLayer->addChild(seer, LevelLayer::sCalcZorder(seer->getPosition()));

			bool isMainLand = MainLandManager::Get()->isMainLand(m_level->m_id);
			int	animID;
			if (isMainLand)
			{
				animID = kTypeIdle_FaceDown_Stand_MAIN;
			}
			else
			{
				animID = kTypeIdle_FaceDown_Stand_OTH;
			}
			
			/*switch(orient)
			{
			case DIRECTION_UP:
			animID = kTypeIdle_FaceUp_Stand_MAIN;
			break;
			case DIRECTION_LEFT:
			break;
			case DIRECTION_BOTTOM:
			break;
			case DIRECTION_RIGHT:
			break;
			default:
			break;
			}*/
			seer->SetAnim(animID,1,true);
		}

		playerInfo.seer = seer;

		//add pet
		//if (petType != 0)
		//{
		//	SpriteElf* elf = LevelObjectCreator::sCreateSpriteElf(petType, 0, true,
		//		MAP_TAG_OTHER_FOLLOW_SPRITE ,
		//		true);

		//	elf->setTag(MAP_TAG_OTHER_FOLLOW_SPRITE);
		//	elf->followSeerPosition(pt, true);
		//	m_level->addChild(elf, LevelLayer::sCalcZorder(elf->getPosition()));

		//	playerInfo.pet = elf;
		//}

		//
		m_level->m_othersPlayerInfo.insert(std::pair<uint32_t, OthersPlayerInfo>(uid, playerInfo));

		CATLObjectLayer* pObjLayer = dynamic_cast<CATLObjectLayer*>(m_level->m_pObjectsLayer);
		if(pObjLayer)
		{
			pObjLayer->AddRoleShadow(seer);
		}

	}
	else
	{
		CCLog("error, the player has add before");
	}
}
Ejemplo n.º 2
0
bool StoryInstanceDirector::TrackPlayerAnim()
{
	// Note: Add To Obj Layer
	LevelLayer* pLayer = LevelManager::sShareInstance()->getCurrentLevelLayer();
	CCNode* pObjLayer = pLayer->getObjectLayer();

	std::map<unsigned int,StoryRoleBasicData> storyData = StoryDataCenter::Get()->GetStoryRoleBasicData();
	std::map<unsigned int,StoryRoleBasicData>::iterator iter = storyData.begin();
	while(iter != storyData.end())
	{
		bool bPosChanged = false;
		SpriteSeer* pCurHero = GetOneRole((*iter).first);

		std::map<unsigned int,StoryFrameData>::iterator frameIter = (*iter).second.mMapStoryFramesData.find((int)m_curFrame);
		if (frameIter != (*iter).second.mMapStoryFramesData.end())
		{
			//// Note: 当前帧存在
			StoryFrameData frameData = (*frameIter).second;
			CCPoint pos = frameData.getRolePos();						

			// Note: 位置发生变化,移动位置,或者新创建角色
			if (StoryFrameData::IsPosChanged(pos))
			{
				bPosChanged = true;

				bool bVisiable = pCurHero->getRoot()->isVisible();
				if (bVisiable == false)
				{
					pCurHero->getRoot()->setVisible(true);
				}
				pCurHero->setPosition(pos);
				pObjLayer->reorderChild(pCurHero,LevelLayer::sCalcZorder(pos));
			}

			int actorId = frameData.getActorId();
			if (actorId != -1)
			{
				pCurHero->SetAnim(actorId,0);
			}

			int nFlip = frameData.getFlip();
			if (nFlip != -1)
			{
				if (nFlip == 0)
				{
					pCurHero->SetAnimFlipX(false);
				}
				else if (nFlip == 1)
				{
					pCurHero->SetAnimFlipX(true);
				}
			}
		}

		if (false == bPosChanged)
		{
			// Note: 不存在的情况下处理移动
			if (false == bPosChanged)
			{
				unsigned int preFrameIndex = 0;
				unsigned int nextFrameIndex = 0;
				CCPoint prePoint = CCPointZero;
				CCPoint nextPoint = CCPointZero;
				if(StoryDataCenter::Get()->GetPreAndNextPointFrameData((*iter).first,(int)m_curFrame,preFrameIndex,nextFrameIndex,prePoint,nextPoint))
				{
					// Note: 处理移动

					unsigned int sumMoveFrames = (nextFrameIndex - preFrameIndex);
					unsigned int runningFrames = (int)m_curFrame - preFrameIndex;
					if (runningFrames >= sumMoveFrames)
					{
						return false;
					}
					// Note: 运动速率
					CCPoint dir = ccpSub(nextPoint,prePoint);
					float distance = sqrt(ccpLengthSQ(dir));
					float vPerFrame = distance/sumMoveFrames;
					if(dir.x == 0 && dir.y == 0)
					{
						return false;
					}
					dir = ccpNormalize(dir);

					CCPoint nowPoint = ccpAdd(prePoint,ccp(vPerFrame*runningFrames*dir.x,vPerFrame*runningFrames*dir.y));
					pCurHero->setPosition(nowPoint);
					pObjLayer->reorderChild(pCurHero,LevelLayer::sCalcZorder(nowPoint));
				}
			}
		}

		iter++;
	}

	return true;
}