本文整理汇总了C++中Coordinate::EnforceMagnitude方法的典型用法代码示例。如果您正苦于以下问题:C++ Coordinate::EnforceMagnitude方法的具体用法?C++ Coordinate::EnforceMagnitude怎么用?C++ Coordinate::EnforceMagnitude使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coordinate
的用法示例。
在下文中一共展示了Coordinate::EnforceMagnitude方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
/**\brief Update function on every frame.
*/
void Ship::Update( lua_State *L ) {
Sprite::Update( L ); // update momentum and other generic sprite attributes
if( status.isAccelerating == false
&& status.isRotatingLeft == false
&& status.isRotatingRight == false) {
flareAnimation->Reset();
}
flareAnimation->Update();
Coordinate momentum = GetMomentum();
momentum.EnforceMagnitude( shipStats.GetMaxSpeed()*engineBooster );
// Show the hits taken as part of the radar color
if(IsDisabled()) SetRadarColor( GREY );
else SetRadarColor( RED * GetHullIntegrityPct() );
// Ship has taken as much damage as possible...
// It Explodes!
if( status.hullDamage >= (float)shipStats.GetHullStrength() ) {
SpriteManager *sprites = Simulation_Lua::GetSimulation(L)->GetSpriteManager();
Camera* camera = Simulation_Lua::GetSimulation(L)->GetCamera();
// Play explode sound
if(OPTION(int, "options/sound/explosions")) {
Sound *explodesnd = Sound::Get("Resources/Audio/Effects/18384__inferno__largex.wav.ogg");
explodesnd->Play( GetWorldPosition() - camera->GetFocusCoordinate());
}
// Create Explosion
sprites->Add( new Effect( GetWorldPosition(), "Resources/Animations/explosion1.ani", 0) );
// Remove this Sprite from the SpriteManager
sprites->Delete( (Sprite*)this );
}
示例2: Accelerate
/**\brief Accelerates the ship.
* \sa Model::GetAcceleration
*/
void Ship::Accelerate( void ) {
Trig *trig = Trig::Instance();
Coordinate momentum = GetMomentum();
float angle = static_cast<float>(trig->DegToRad( GetAngle() ));
float speed = shipStats.GetMaxSpeed()*engineBooster;
float acceleration = (shipStats.GetForceOutput() *engineBooster ) / shipStats.GetMass();
momentum += Coordinate( trig->GetCos( angle ) * acceleration * Timer::GetDelta(),
-1 * trig->GetSin( angle ) * acceleration * Timer::GetDelta() );
momentum.EnforceMagnitude(speed);
SetMomentum( momentum );
status.isAccelerating = true;
// Play engine sound
float engvol = OPTION(float,"options/sound/engines");
Coordinate offset = GetWorldPosition() - Camera::Instance()->GetFocusCoordinate();
if ( this->GetDrawOrder() == DRAW_ORDER_SHIP )
engvol = engvol * NON_PLAYER_SOUND_RATIO ;
this->engine->GetSound()->SetVolume( engvol );
this->engine->GetSound()->PlayNoRestart( offset );
}