Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 private void ListenForEndOfIntro()
 {
     SpaceTime.Add(TimeFunction.Create(() =>
     {
         var remainingCount = SpaceTime.Elements.Where(e => e is FlammableLetter || e is Fire).Count();
         if (remainingCount == 0)
         {
             Cleanup();
         }
     }));
 }
Esempio n. 3
0
        private void PlaySceneInternal()
        {
            // reveal the PowerArgs logo
            factory.InitializeScene(level).ForEach(e => SpaceTime.Add(e));
            // create the character
            character = new MainCharacter();
            // he starts a few pixels from the right edge
            character.MoveTo(Width - 7, 0);
            // he moves to the right
            character.Speed.SpeedX = 5;
            // he drops a timed mine and turns around when he gets near the right edge
            ListenForCharacterNearRightEdge();

            SpaceTime.Add(character);

            ListenForEndOfIntro();
        }
Esempio n. 4
0
        public void TestTimePerf()
        {
            var t   = new SpaceTime(80, 30, TimeSpan.FromSeconds(.05));
            var now = TimeSpan.Zero;

            t.Invoke(async() =>
            {
                for (var i = 0; i < 10000; i++)
                {
                    t.Add(new DummyFunction());
                }

                while (t.Now < TimeSpan.FromSeconds(100000))
                {
                    Assert.AreEqual(now, t.Now);
                    now = now.Add(t.Increment);
                    await t.YieldAsync();
                }
                t.Stop();
            });

            t.Start().Wait();
        }