Example #1
0
bool TouchWheel::touchOnLoaction(Vector2 point)
{ 
    if(ccpLengthSQ(point) >= sq(m_innerRadius))
    {
        if(ccpLengthSQ(point) > sq(m_touchRadius))
            point = ccpNormalize(point)*m_touchRadius;

        if(m_innerRadius > 0)
            m_touchPoint = (point - (ccpNormalize(point)*m_innerRadius))/(m_touchRadius- m_innerRadius);
        else
            m_touchPoint = point/m_touchRadius;
        
        if(m_touchSprite)
        {
            m_touchSprite->setRotation(angleForVector2(point)); 
            m_touchSprite->setPosition(point);
            m_touchSprite->setIsVisible(true);
        }
        return true;
    }
    else 
    {
        m_touchPoint = POINT_ZERO;
        if(m_touchSprite)
        {
            m_touchSprite->setIsVisible(false);
        }
        return false;
    }
}
Example #2
0
unsigned int ElfBaseState::GetFollowPointType(unsigned int skillId,bool bRelayVerDir /* = false */)
{
	switch(skillId)
	{
	case kTypeIdle_FaceHor_Stand_MAIN:
	case kTypeIdle_FaceHor_Stand_OTH:
	case kTypeRun_FaceHor_MAIN:
	case kTypeRun_FaceHor_OTH:
		{
			bool bFlipX = m_pRole->IsAnimFlipX();
			if (bFlipX)
			{
				return 0;
			}
			return 1;
		}
		break;
	case kTypeIdle_FaceDown_Stand_MAIN:
	case kTypeIdle_FaceDown_Stand_OTH:
	case kTypeIdle_FaceUp_Stand_MAIN:
	case kTypeIdle_FaceUp_Stand_OTH:
	case kTypeRun_FaceDown_MAIN:
	case kTypeRun_FaceDown_OTH:
	case kTypeRun_FaceUp_MAIN:
	case kTypeRun_FaceUp_OTH:
		{
			if (bRelayVerDir)
			{
				CCPoint elfPos = m_pElf->getPosition();
				CCPoint pointLeft = m_pElf->GetMoveTargetPos(true);
				CCPoint pointRight = m_pElf->GetMoveTargetPos(false);

				float disLeft = ccpLengthSQ(ccpSub(elfPos,pointLeft));
				float disRight = ccpLengthSQ(ccpSub(elfPos,pointRight));

				if(disLeft <= disRight)
				{
					return 0;
				}
				else
				{
					return 1;
				}
			}
		}
		break;
	}
	return -1;
}
Example #3
0
void EXZoomController::endScroll(CCPoint pos) {
    unschedule(schedule_selector(EXZoomController::updateTime));
	
    //Only perform a velocity scroll if we have a good amount of history
	if (_timePointStampCounter > 3) {
        //calculate velocity
        CCPoint velocity = ccpMult(getHistoricSpeed(), swipeVelocityMultiplier * _node->getScale());
        
        //Make sure we have a reasonable speed (more than 5 pts away)
		if (ccpLengthSQ(velocity) > 5*5) {
            //caculate  position of swipe action
			CCPoint newPos = ccpAdd(_node->getPosition(), velocity);
			newPos = boundPos(newPos);
			
            //create the action
			CCMoveTo* moveTo = CCMoveTo::create(scrollDuration, newPos);
			CCEaseOut* ease = CCEaseOut::create(moveTo, 3);
			CCLOG("stop 1");
            //unconditional stop; cocos handles this properly
			_node->stopAction(_lastScrollAction);
			_node->runAction(ease);
            
            //release our last action since we retain it below
            if (_lastScrollAction) {
                _lastScrollAction->release();
                _lastScrollAction = NULL;
            }
            CCLOG("stop end");

            _lastScrollAction = ease;
            _lastScrollAction->retain();
		}
	}
}
Example #4
0
NS_CC_BEGIN

#define kCCPointEpsilon    FLT_EPSILON

float
ccpLength(const CCPoint& v)
{
    return sqrtf(ccpLengthSQ(v));
}
Example #5
0
void NDUIXBoardHitProxy::UITouchMoved(NDTouch* pkTouch)
{
	NDUILayer* pkLayer = 0;

	if (!canProcessTouch(pkLayer))
	{
		if (pkLayer)
		{
			pkLayer->UITouchMoved(pkTouch);
		}

		return;
	}

	if (!IsVisible())
	{
		return;
	}

	if (m_bEnableMove)
	{
		assert(m_pkOwner && pkTouch);
		CCPoint kDeltaPosition = ccpSub(pkTouch->GetLocation(),
			pkTouch->GetPreviousLocation());

		if (ccpLengthSQ(kDeltaPosition) >= 16 * 16)
		{
			m_bIsMoving = true;
		}

		m_pkOwner->getBoard()->move(kDeltaPosition.x, kDeltaPosition.y);
	}
	else
	{
		for (int i = 0; i < m_pkOwner->getViewCount(); i++)
		{
			NDUIXView* pkView = m_pkOwner->getViewAt(i);
			if (pkView && pkView->GetEnabled()
				&& pkView->GetScreenRect().containsPoint(
				pkTouch->GetLocation()))
			{
				pkView->UITouchMoved(pkTouch);

				break;
			}
		}
	}
}
Example #6
0
bool TouchWheel::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
    CCPoint touch = CCDirector::sharedDirector()->convertToGL(pTouch->locationInView());
    CCPoint local = this->convertToNodeSpace(touch);
    float distanceSQ = ccpLengthSQ(local);
    if(distanceSQ > sq(m_touchRadius))
        return false;


    if(m_touchSprite)
    {
        m_touchSprite->setIsVisible(true);
    }
    touchOnLoaction(local);
    
    if(m_handler)
        m_handler->wheelTouchBegan(this, m_touchPoint);


    schedule(schedule_selector(TouchWheel::touchUpdate));
    return true;
}
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;
}
Example #8
0
void ElfCloseToState::Update(float dt)
{
	ElfBaseState::Update(dt);

	if (m_isMoveEnd)
	{
		return ;
	}

	unsigned int roleActionId = m_pRole->GetAnimID();
	unsigned int followPointType = GetFollowPointType(roleActionId);
	if (followPointType != -1)
	{
		if (followPointType != m_followPointType)
		{
			m_followPointType = followPointType;
			Reset();
			return ;
		}
	}

	if (m_fGoTime < m_accTotalTime)
	{
		CCPoint elfPos = m_pElf->getPosition();
		m_fGoTime += dt;
		m_fMoveSpeed = m_fGoTime * m_accelateRate + m_maxSpeed*m_startSpeedCoefficient;
		if (m_fMoveSpeed >= m_maxSpeed)
		{
			m_fMoveSpeed = m_maxSpeed;
		}
	}
	else
	{
		m_fMoveSpeed = m_maxSpeed;
	}

	CCPoint targetPoint = GetCloseToHeroPoint(m_followPointType);
	CCPoint elfPos = m_pElf->getPosition();

	CCPoint dir = ccpSub(targetPoint, elfPos);
	float dirLength = sqrt(ccpLengthSQ(dir));
	if (IsInOuterCircle(dirLength))
	{
		SpriteElfManager::Get()->PushOneElfChaseState(m_pRole,0);
		return ;
	}

	unsigned int animId = m_pRole->GetAnimID();
	if (animId == kTypeIdle_FaceHor_Stand_MAIN ||
		animId == kTypeIdle_FaceHor_Stand_OTH ||
		animId == kTypeIdle_FaceDown_Stand_MAIN ||
		animId == kTypeIdle_FaceDown_Stand_OTH ||
		animId == kTypeIdle_FaceUp_Stand_MAIN ||
		animId == kTypeIdle_FaceUp_Stand_OTH
		)
	{
		if(dirLength <= 1)
		{
			bool bFlip = false;
			unsigned int roleActionId = m_pRole->GetAnimID();
			unsigned int animDirectionId = GetAnimDirection(roleActionId);
			unsigned int animID = GetAnimId(animDirectionId,bFlip);

			m_pElf->SetAnim(animID,0);
			m_pElf->SetAnimFlipX(bFlip);
			m_isMoveEnd = true;

			return ;
		}
	}

	if(dir.x != 0 || dir.y != 0)
	{
		dir = ccpNormalize(dir);
	}
	else
	{
		return ;
	}

	float speed = m_fMoveSpeed;

	float newPosX = elfPos.x + dt*speed*dir.x;
	float newPosY = elfPos.y + dt*speed*dir.y;

	// Note: 修复位置误差
	CCPoint newElfTempPos(newPosX,newPosY);
	CCPoint elfToTargetDir = ccpNormalize(ccpSub(targetPoint,elfPos));
	CCPoint newPosToTargetDir = ccpNormalize(ccpSub(targetPoint,newElfTempPos));
	if (elfToTargetDir.x * newPosToTargetDir.x <0 
		|| elfToTargetDir.y * newPosToTargetDir.y <0 )
	{
		m_pElf->setPosition(targetPoint);
		return ;
	}


	m_pElf->setPosition(ccp(newPosX,newPosY));

	// Note: 更新方向
	bool bFlip = false;
	unsigned int animDirectionId = GetAnimDirection(dir);
	unsigned int animID = GetAnimId(animDirectionId,bFlip);
	if (animID != m_tempAnimDirection)
	{
		m_pElf->SetAnim(animID,0);
		m_pElf->SetAnimFlipX(bFlip);

		m_tempAnimDirection = animID;
		m_isFlip = bFlip;
	}
	else if(bFlip != m_isFlip)
	{
		m_pElf->SetAnimFlipX(bFlip);
		m_isFlip = bFlip;
	}
}
CGFloat
ccpLength(const CCPoint v)
{
	return sqrtf(ccpLengthSQ(v));
}
Example #10
0
float CC_DLL ccpLength(const CCPoint& v)
{
	return sqrtf(ccpLengthSQ(v));
}