Пример #1
0
        /// <summary>
        /// 播放MadeWithDestroy的动画
        /// </summary>
        /// <param name="center">是否居中显示</param>
        /// <param name="x">横向坐标</param>
        /// <param name="y">纵向坐标</param>
        /// <param name="consoleKey">按键</param>
        public static void MadeWithDestroy(bool center, short x, short y, ConsoleKey consoleKey = ConsoleKey.Enter)
        {
            string logo = "Made with Destroy";

            if (center)
            {
                x  = (short)(CONSOLE.WindowWidth / 2);
                x -= (short)(logo.Length / 2);
                y  = (short)(CONSOLE.WindowHeight / 2);
            }
            CONSOLE.SetCursorPosition(x, y);
            CONSOLE.ForegroundColor = Colour.Black;
            CONSOLE.BackgroundColor = Colour.White;
            CONSOLE.Write(logo);
            CONSOLE.ResetColor();
            CONSOLE.SetCursorPosition(0, 0);
            //窗口透明度渐变
            for (int i = 0; i < 256; i++)
            {
                //按下回车键直接恢复透明度并且退出渐变阶段
                if (CONSOLE.GetKey(consoleKey))
                {
                    KERNEL.SET_WINDOW_ALPHA(255);
                    break;
                }
                KERNEL.SET_WINDOW_ALPHA((byte)i);
                KERNEL.SLEEP(10);
            }
            KERNEL.SLEEP(1000);
            CONSOLE.Clear();
        }
Пример #2
0
        /// <summary>
        /// 开始游戏
        /// </summary>
        public static void Start(Action onStart, Action onUpdate, Action onDestroy, int fps)
        {
            run = true;
            //这一帧距离上一帧的时间(单位:秒)
            float deltaTime = 0;
            //每帧应该使用的时间(单位:毫秒)
            long tickTime = 1000 / fps;
            //代码一帧运行花费的时间(单位:毫秒)
            long timeCost = 0;

            //初始化游戏
            onStart?.Invoke();

            while (run)
            {
                KERNEL.START_TIMING(out long freq, out long start);

                //每帧执行一次, 防止控制台窗口大小变化时光标再次出现
                KERNEL.SET_CONSOLE_CURSOR_INFO(CONSOLE.OutputHandle, false, 1);
                Time.DeltaTime  = deltaTime;        //赋值DeltaTime
                Time.TotalTime += Time.DeltaTime;   //赋值TotalTime
                Input.CheckMouseState();            //检测鼠标状态
                onUpdate?.Invoke();                 //每帧更新游戏
                Input.CheckKeyboardState();         //检测键盘状态

                KERNEL.END_TIMING(freq, start, out timeCost);

                while (timeCost < tickTime)
                {
                    KERNEL.SLEEP(0);                //短暂让出线程防止死循环
                    KERNEL.END_TIMING(freq, start, out timeCost);
                }

                deltaTime = (float)timeCost / 1000;
            }

            //结束游戏
            onDestroy?.Invoke();
        }