示例#1
0
        static void Main(string[] args)
        {
            /*
             * Utils.DrawChar('A', 10, 10);
             * Console.ReadKey();
             */

            //Controlar fps
            int      fps               = 0;
            int      desiredFPS        = 30;
            double   inverseDesiredFPS = 1.0 / desiredFPS;
            DateTime currentTime;
            TimeSpan deltaTime;

            int      frameCount  = 0;
            DateTime lastTime    = DateTime.Now;
            double   elapsedTime = 0;

            var game = new Game();

            game.Initialize();

            while (true)
            {
                game.Input();
                game.Update();
                game.Draw();

                //Console.SetCursorPosition(0, 21);
                //Console.WriteLine("");
                //Console.WriteLine($"FPS: {fps}/{inverseDesiredFPS}/{desiredFPS}");

                currentTime = DateTime.Now;
                deltaTime   = currentTime - lastTime;

                elapsedTime += deltaTime.TotalSeconds;

                while (deltaTime.TotalSeconds <= inverseDesiredFPS)
                {
                    deltaTime = DateTime.Now - lastTime;
                }

                if (elapsedTime >= 1)
                {
                    fps        = frameCount;
                    frameCount = 0;
                    elapsedTime--;
                }

                lastTime = currentTime;

                frameCount++;
            }
        }