///<summary>Runs the game loop until the game ends.</summary>
        public async static Task Loop(this Game game) {
            var clock = new Stopwatch();
            clock.Start();

            var lastTime = clock.Elapsed;
            while (!game.Life.IsDead) {
                var dt = clock.Elapsed - lastTime;
                lastTime += dt;

                var step = new GameStep(timeStep: dt.Clamp(TimeSpan.Zero, TimeSpan.FromSeconds(1)));
                foreach (var e in game.LoopActions.CurrentItems())
                    e.Value.Invoke(step);

                await Task.Delay(30.Milliseconds());
            }
        }
Esempio n. 2
0
        ///<summary>Runs the game loop until the game ends.</summary>
        public async static Task Loop(this Game game)
        {
            var clock = new Stopwatch();

            clock.Start();

            var lastTime = clock.Elapsed;

            while (!game.Life.IsDead)
            {
                var dt = clock.Elapsed - lastTime;
                lastTime += dt;

                var step = new GameStep(timeStep: dt.Clamp(TimeSpan.Zero, TimeSpan.FromSeconds(1)));
                foreach (var e in game.LoopActions.CurrentItems())
                {
                    e.Value.Invoke(step);
                }

                await Task.Delay(30.Milliseconds());
            }
        }