示例#1
0
        public Main()
        {
            self = this;

            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // Set Width and Height og game screen
            graphics.PreferredBackBufferWidth  = Settings.Default.ScreenWidth;
            graphics.PreferredBackBufferHeight = Settings.Default.ScreenHeight;

            // Set windows start posion to center screen
            Window.Position = new Point((GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width / 2) - (graphics.PreferredBackBufferWidth / 2), (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / 2) - (graphics.PreferredBackBufferHeight / 2));

            // For detect FPS in FramerateCounter.cs
            graphics.SynchronizeWithVerticalRetrace = false;
            IsFixedTimeStep = false;

            // Restore fullscreen setting
            if (Settings.Default.FullScreen)
            {
                graphics.ToggleFullScreen();
            }
            graphics.ApplyChanges();

            // Initial ScreenTransition
            ScreenTransitions.FadeOUT();

            // Initial QuakeConsole
            console = new ConsoleComponent(this);
            Components.Add(console);

            // Add interpreter for QuakeConsole
            pythonInterpreter   = new PythonInterpreter();
            manualInterpreter   = new ManualInterpreter();
            console.Interpreter = manualInterpreter;

            // Add variable for PythonInterpreter
            pythonInterpreter.AddVariable("console", console);
            pythonInterpreter.AddVariable("manual", manualInterpreter);

            // Add command for ManualInterpreter
            manualInterpreter.RegisterCommand("fullscreen", args => {
                if (args.Length == 0)
                {
                    return;
                }
                else if (graphics.IsFullScreen && args[0].Equals("off"))
                {
                    graphics.ToggleFullScreen();
                }
                else if (!graphics.IsFullScreen && args[0].Equals("on"))
                {
                    graphics.ToggleFullScreen();
                }
            });
            manualInterpreter.RegisterCommand("fps", args => {
                if (args.Length == 0)
                {
                    return;
                }
                else if (args[0].Equals("on"))
                {
                    Settings.Default.ShowFPS = true;
                    Settings.Default.Save();
                }
                else if (args[0].Equals("off"))
                {
                    Settings.Default.ShowFPS = false;
                    Settings.Default.Save();
                }
            });
            manualInterpreter.RegisterCommand("Level", args => {
                if (args.Length < 2)
                {
                    return;
                }
                else if (args[0].Equals("="))
                {
                    Settings.Default.LevelSelected = int.Parse(args[1]);
                    Settings.Default.Save();
                }
            });
            manualInterpreter.RegisterCommand("console.Interpreter", args => {
                if (args.Length < 2)
                {
                    return;
                }
                else if (args[0].Equals("=") & args[1].Equals("python"))
                {
                    console.Interpreter = pythonInterpreter;
                }
            });
            manualInterpreter.RegisterCommand("exit", args => { Exit(); });
            manualInterpreter.RegisterCommand("ResetLevel", args => { ScreenManager.LoadScreen(new GamePlayScreen()); });

            BGM = Content.Load <Song>("Audios/POL-mad-run-short");
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Volume      = Settings.Default.BGMVolume;
            MediaPlayer.Play(BGM);

            AudioManager.AddAudioEffect("click", Content.Load <SoundEffect>("Audios/NFF-select").CreateInstance());
            AudioManager.AddAudioEffect("shoot", Content.Load <SoundEffect>("Audios/NFF-rasp").CreateInstance());
            AudioManager.AddAudioEffect("die", Content.Load <SoundEffect>("Audios/NFF-lose").CreateInstance());
            AudioManager.AddAudioEffect("switch", Content.Load <SoundEffect>("Audios/NFF-click-switch").CreateInstance());
        }