void ADraggableMoveTile::UpdateDragMove(float dt)
{
	if (isMoving)
	{
		auto moveDir = (newGoalPos - GetActorLocation()).GetSafeNormal();
		auto reachedPos = FVector::DotProduct(currDir, moveDir) < 0.0f;

		if (reachedPos || reachGoalNextFrame)
		{
			SetActorLocation(newGoalPos);
			isMoving = false;
			reachGoalNextFrame = false;
			resetIndicator();

		}
		else if (moveDir.SizeSquared() > 0.1f)
		{
			auto deltaMovement = moveDir * dragMoveSpeed * dt;
			SetActorLocation(GetActorLocation() + deltaMovement);

			auto nextFramePos = GetActorLocation() + deltaMovement;
			moveDir = (newGoalPos - nextFramePos).GetSafeNormal();
			reachGoalNextFrame = FVector::DotProduct(currDir, moveDir) < 0.0f;
		}
	}
}
void ADraggableMoveTile::Initialize()
{
	if (currentVertex != nullptr)
	{
		auto newLocation = currentVertex->GetActorLocation();
		newLocation.Z -= 10.0f;
		SetActorLocation(newLocation);
		currentVertex->SetOccupied(true);
	}

	if (carryOn != nullptr)
	{
		if (auto actor = Cast<ICarriable>(carryOn))
		{
			auto scale = actor->getOffsetInfo().scaleForCollision;
			auto offset = actor->getOffsetInfo().offsetForCollision;
			BoxCollision->SetRelativeScale3D(scale);
			BoxCollision->AddLocalOffset(offset);
		}
	}
	else
	{
		BoxCollision->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Block);
	}

	resetIndicator();
}
Esempio n. 3
0
void Altimeter::onUpdateActivity(float dt)
{
    _timeout -= dt;
    if( _timeout < 0 ) _timeout = 0;

    if( _timeout > 0 )
    {
        // reset HUD
        resetIndicator( _window->getPanel()->find( "Digit5" ) );
        resetIndicator( _window->getPanel()->find( "Digit4" ) );
        resetIndicator( _window->getPanel()->find( "Digit3" ) );
        resetIndicator( _window->getPanel()->find( "Digit2" ) );
        resetIndicator( _window->getPanel()->find( "Digit1" ) );
        resetIndicator( _window->getPanel()->find( "Digit0" ) );
        resetIndicator( _window->getPanel()->find( "AuDigit5" ) );
        resetIndicator( _window->getPanel()->find( "AuDigit4" ) );
        resetIndicator( _window->getPanel()->find( "AuDigit3" ) );
        resetIndicator( _window->getPanel()->find( "AuDigit2" ) );
        resetIndicator( _window->getPanel()->find( "AuDigit1" ) );
        resetIndicator( _window->getPanel()->find( "AuDigit0" ) );
    }
    else
    {
        // retrieve parent actor altitude
        Matrix4f parentPose = _parent->getPose();
        float altitude = parentPose[3][1];

        // draw signum digit
        setSignumIndicator( _window->getPanel()->find( "Digit5" ), altitude );        

        // absolute units conversion
        float meters = fabs( altitude ) * 0.01f;
        int units = int( meters );

        // digits pickup
        int digit = units % 10;
        setIndicator( _window->getPanel()->find( "Digit0" ), digit );
    
        units = units / 10;
        digit = units % 10;
        setIndicator( _window->getPanel()->find( "Digit1" ), digit );

        units = units / 10;
        digit = units % 10;
        setIndicator( _window->getPanel()->find( "Digit2" ), digit );

        units = units / 10;
        digit = units % 10;
        setIndicator( _window->getPanel()->find( "Digit3" ), digit );

        units = units / 10;
        digit = units % 10;
        setIndicator( _window->getPanel()->find( "Digit4" ), digit );

        // update audible altimeter
        gui::IGuiPanel* auCaption = _window->getPanel()->find( "AuCaption" );
        assert( auCaption && auCaption->getStaticText() );
        if( _state->mode )
        {        
            auCaption->getStaticText()->setText( Gameplay::iLanguage->getUnicodeString(217) );
        }
        else
        {
            auCaption->getStaticText()->setText( Gameplay::iLanguage->getUnicodeString(216) );
        }        

        // audible altimeter signum indicator
        setSignumIndicator( _window->getPanel()->find( "AuDigit5" ), _state->altitude );

        // absolute units conversion
        meters = fabs( _state->altitude ) * 0.01f;
        units = int( meters );

        // digits pickup
        digit = units % 10;
        setIndicator( _window->getPanel()->find( "AuDigit0" ), digit );
    
        units = units / 10;
        digit = units % 10;
        setIndicator( _window->getPanel()->find( "AuDigit1" ), digit );

        units = units / 10;
        digit = units % 10;
        setIndicator( _window->getPanel()->find( "AuDigit2" ), digit );

        units = units / 10;
        digit = units % 10;
        setIndicator( _window->getPanel()->find( "AuDigit3" ), digit );

        units = units / 10;
        digit = units % 10;
        setIndicator( _window->getPanel()->find( "AuDigit4" ), digit );

        // helpers act
        _acAMTimeout  -= dt;
        _acIWATimeout -= dt;
        _acDWATimeout -= dt;
        if( _acAMTimeout < 0 ) _acAMTimeout = 0;
        if( _acIWATimeout < 0 ) _acIWATimeout = 0;
        if( _acDWATimeout < 0 ) _acDWATimeout = 0;

        // altimeter control
        ActionChannel* acAM  = Gameplay::iGameplay->getActionChannel( ::iaAltimeterMode );
        ActionChannel* acIWA = Gameplay::iGameplay->getActionChannel( ::iaIncreaseWarningAltitude );
        ActionChannel* acDWA = Gameplay::iGameplay->getActionChannel( ::iaDecreaseWarningAltitude );
        assert( acAM );
        assert( acIWA );
        assert( acDWA );

        if( !acAM->getTrigger() ) _acAMTimeout = 0;
        if( !acIWA->getTrigger() ) _acIWATimeout = 0;
        if( !acDWA->getTrigger() ) _acDWATimeout = 0;

        if( acAM->getTrigger() && _acAMTimeout == 0 )
        {
            _acAMTimeout = acAMTimeout;
            if( _state->mode )
            {
                _toneSound->release();
                _toneSound = NULL;
            }
            _state->mode = !_state->mode;
            if( _state->mode )
            {
                _toneSound = Gameplay::iAudio->createStaticSound( "./res/sounds/hud/aualt0.ogg" );
                _toneSound->setLoop( true );
            }
        }
        if( acIWA->getTrigger() && _acIWATimeout == 0 )
        {
            _acIWATimeout = acXWATimeout;
            _state->altitude += 1000;
        }
        if( acDWA->getTrigger() && _acDWATimeout == 0 )
        {
            _acDWATimeout = acXWATimeout;
            _state->altitude -= 1000;
        }

        // play tone sound
        if( altitude < _state->altitude && _toneSound )            
        {
            if( !_toneSound->isPlaying() ) _toneSound->play();
        }
        else if( _toneSound )
        {
            if( _toneSound->isPlaying() ) _toneSound->stop();
        }
    }
}