void CProjectile::Update(CTime elapsedTime) { mShape.move(mVelocity * elapsedTime.asSeconds()); if (!IsActive()) { mDeathTime -= elapsedTime; if (mDeathTime <= CTime::Zero) { MarkAsDead(); } } }
// ============================================================================= // CPullingSwing::Update // ----------------------------------------------------------------------------- void CPullingSwing::Update(CTime elapsedTime) { DetachIfAnchorIsNotValid(); if (mAttached) { // Update the length since the player will be closer now mLength = GetDistanceToBob(); // Detach the player if they are close enough if (mLength <= smDetachLength) { Detach(); } else { // Make sure the players velocity is towards the origin CVector2f v = mBob->GetVelocity(); CVector2f bobToOrigin = mOrigin - mBob->GetPosition(); bobToOrigin.Normalise(); v = v.GetComponentInDirection(bobToOrigin); // Accelerate the player towards the origin float timedInc = smPullSpeedIncrement * elapsedTime.asSeconds(); CVector2f newV = v + (bobToOrigin * timedInc); // Clamp the new velocity if (newV.GetMagnitude() > smPullSpeedMax) { newV = bobToOrigin * smPullSpeedMax; } mBob->SetVelocity(newV); } } }