/// <summary> /// Update our beam's opacity - first fades in and then out. /// Continue to play the firing sfx until we are done. /// </summary> /// <param name="elapsedGameTime"></param> public override void Update(float elapsedGameTime) { base.Update(elapsedGameTime); if (!fadeOut) { // Keep increasing opacity CurrentOpacityLerp += 2 * elapsedGameTime; if (CurrentOpacityLerp >= 1) { // If we have reached full opacity we fade out fadeOut = true; // Trigger the event when at full opacity ExplosionSFX.Play(); Target.OnCollisionWith(this); } } else { // Lerp out CurrentOpacityLerp -= 2 * elapsedGameTime; if (CurrentOpacityLerp <= 0) { // Die when we reach 0 opacity again Die(); } } Opacity = MathHelper.Lerp(0, 1, CurrentOpacityLerp); }
/// <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> /// 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); // This bullet may have been killed by a lifetime module or something, so do not register the collision if this is the case - the bullet has died! if (!IsAlive) { return; } 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); } }