Exemplo n.º 1
0
void Player::update(float dt)
{
    float smoothedAngle =std::min(std::max(targetAngle*(1-dt*returnSpeed*(rollReturnThreshold-fabsf(targetAngle)/maxRoll)),-maxRoll),maxRoll);
    setRotation3D(Vec3(fabsf(smoothedAngle)*0.15,smoothedAngle, 0));
    targetAngle = getRotation3D().y;
    
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    this->onAxisRepeat();
    this->onKeyRepeat();
#endif
    
}
Exemplo n.º 2
0
bool BaseCar::init(std::string fileName , float originVelo, cocos2d::Vec2 originPos , int direction)
{
    this->initWithFile(fileName);
    _normalRes = fileName;
    _originAngle = getRotation3D().z;
    _direction = direction;
    _originVelo = originVelo;
    _originPos = originPos;
    setVelo(originVelo , true);
    setPosition(originPos);
    initFSM();
    return true;
}
Exemplo n.º 3
0
void BaseCar::circleUpdate(float d)
{
    auto UDLR = getUDLR();

    if (UDLR == up || UDLR == down) {
        _delayedStateName = CarState::Line;
    }

    auto winSize = Director::getInstance()->getWinSize();
    auto centerPos = Vec2(winSize.width / 2 , winSize.height / 2);
    auto pos = getPosition();

    //base of 180°
    auto rotateZ = getRotation3D().z;

    auto curAngle = convertToPI(- rotateZ) + PI / 2;

    double newAngle;

    switch (_direction) {
    case Direction::CCW:
        newAngle = curAngle + _angVelo * d;
        if (pos.x < centerPos.x) {
            setPositionX(POS_L.x + cos(newAngle) * _curRadius);
            setPositionY(POS_L.y + sin(newAngle) * _curRadius);
        }
        else {
            setPositionX(POS_R.x + cos(newAngle) * _curRadius);
            setPositionY(POS_R.y + sin(newAngle) * _curRadius);
        }
        break;

    case Direction::CW:
        newAngle = curAngle - _angVelo * d;
        if (pos.x < centerPos.x) {
            setPositionX(POS_L.x + cos(newAngle) * _curRadius);
            setPositionY(POS_L.y + sin(newAngle) * _curRadius);
        }
        else {
            setPositionX(POS_R.x + cos(newAngle) * _curRadius);
            setPositionY(POS_R.y + sin(newAngle) * _curRadius);
        }
        break;

    default:
        break;
    }
    setRotation3D(Vec3(0 , 0 , - convertTo180(newAngle - PI / 2)));
}