/// <summary> /// Updates our bullet's position and kill's it if it has collided with our target /// </summary> /// <param name="elapsedGameTime"></param> public override void Update(float elapsedGameTime) { base.Update(elapsedGameTime); // The missile may have been killed by a lifetime module already so we should not progress any further with it's updating if (!IsAlive) { return; } if (!finishedJutting) { LocalPosition = Vector2.Lerp(LocalPosition, jutFinishPosition, 5 * elapsedGameTime); if ((LocalPosition - jutFinishPosition).LengthSquared() < 10) { finishedJutting = true; Engine.Show(); // Have to call show because by default our Engine is hidden (since it is a CardObject) FiringSFX.Play(); } } else { Vector2 diff = Target.WorldPosition - WorldPosition; diff.Normalize(); float angle = MathUtils.AngleBetweenPoints(WorldPosition, Target.WorldPosition); LocalRotation = angle; LocalPosition += diff * 700 * elapsedGameTime; DebugUtils.AssertNotNull(Collider); DebugUtils.AssertNotNull(Target.Collider); if (Collider.CheckCollisionWith(Target.Collider)) { // Kills the projectile if it has collided with the target Die(); ExplosionSFX.Play(); Target.OnCollisionWith(this); } } }
/// <summary> /// Play our firing sound effect /// </summary> public override void Begin() { base.Begin(); FiringSFX.Play(); }