private void ListenForCharacterNearRightEdge() { ITimeFunction watcher = null; watcher = TimeFunction.Create(() => { if (character.Left > Width - 2) { // turn the character around so he now moves to the left character.Speed.SpeedX = -8; // drop a timed mine var dropper = new TimedMineDropper() { Delay = TimeSpan.FromSeconds(4), AmmoAmount = 1, Holder = character }; dropper.Exploded.SubscribeOnce(() => Sound.Play("PowerArgsIntro")); dropper.FireInternal(); // eventually he will hit the left wall, remove him when that happens character.Speed.ImpactOccurred.SubscribeForLifetime((i) => character.Lifetime.Dispose(), character.Lifetime); // this watcher has done its job, stop watching the secne watcher.Lifetime.Dispose(); } }); SpaceTime.Add(watcher); }
private void ListenForCharacterNearRightEdge() { SpaceTime.Invoke(async() => { while (SpaceTime.IsRunning) { if (character.Left > Width - 2) { // turn the character around so he now moves to the left character.Velocity.Speed = 8; character.Velocity.Angle = 180; // drop a timed mine var dropper = new TimedMineDropper() { Delay = TimeSpan.FromSeconds(4), AmmoAmount = 1, Holder = character }; dropper.Exploded.SubscribeOnce(() => Sound.Play("PowerArgsIntro")); dropper.FireInternal(false); // eventually he will hit the left wall, remove him when that happens character.Velocity.ImpactOccurred.SubscribeForLifetime((i) => character.Lifetime.Dispose(), character.Lifetime); // this watcher has done its job, stop watching the secne break; } await SpaceTime.YieldAsync(); } }); }