void EnemyBase::runFollowPoint()
{
	auto point = currPoint();
	auto prevP = point;
	setPosition(point->getPosition());
	point = nextPoint();
	auto nextP = point;

	if (point != nullptr)
	{

		float distancePrevToNext;
		//计算2个点的距离差,保证匀速运动
		if (abs(prevP->getPosition().x - nextP->getPosition().x) <= abs(prevP->getPosition().y - nextP->getPosition().y))
		{
			distancePrevToNext = abs(prevP->getPosition().y - nextP->getPosition().y);
		}
		else
		{
			distancePrevToNext = abs(prevP->getPosition().x - nextP->getPosition().x);
		}

		float timeToMove = distancePrevToNext / (getRunSpeed()*20.0);

		runAction(Sequence::create(MoveTo::create(timeToMove, point->getPosition())
			, CallFuncN::create(CC_CALLBACK_0(EnemyBase::runFollowPoint, this))
			, NULL));
	}
	else
	{
		//setEnemySuccessful(true);
	}
}
Example #2
0
void Tremor::restartWalking()
{
	baseSprite->stopAllActions();
	setState(tempState);

	auto tempCurrPoint = baseSprite->getPosition();
	auto duration =  tempCurrPoint.getDistance(tempNextPoint) / getRunSpeed() ;
	baseSprite->runAction(Sequence::create(MoveTo::create(duration, tempNextPoint)
                                           , CallFuncN::create(CC_CALLBACK_0(Tremor::runNextPoint, this))
                                         , NULL));
}
Example #3
0
void Role::updateMoving()
{
    Vec2 pos = getPosition();
    float x = pos.x;
    float y = pos.y;
    
    switch (mMovingState)
    {
        case MOVING_RUN:
            if (mIsFaceLeft) x -= getRunSpeed();
            else x += getRunSpeed();
            setPosition(Vec2(x, y));
            break;
            
        case MOVING_WALK:
            if (mIsFaceLeft) x -= getWalkSpeed();
            else x += getWalkSpeed();
            setPosition(Vec2(x, y));
            break;
    }
}
Example #4
0
Vec2 Role::getMovingScope()
{
    float y = 0.0f;
    float x = 0.0f;
    switch (mMovingState)
    {
        case MOVING_WALK:
            x = getWalkSpeed();
            break;
            
        case MOVING_RUN:
            x = getRunSpeed();
            break;
    }
    
    return Vec2(x, y);
}