Esempio n. 1
0
        private static void Main(string[] args)
        {
            //Window set up.
            Window = new RenderWindow(new VideoMode(550, 104), "Smus", Styles.None);
            Window.SetFramerateLimit(61);
            Window.GainedFocus        += (o, e) => { WindowFocused = true; };
            Window.LostFocus          += (o, e) => { WindowFocused = false; };
            Window.MouseButtonPressed += (o, e) =>
            {
                //Hack to fix window focus.
                if (!WindowFocused)
                {
                    Window.Position += new Vector2i(0, 0);
                }
            };

            //Make sure the window can close properly.
            Window.Closed += (o, e) => Window.Close();
            Window.Closed += (o, e) => { if (Audio.Engine != null)
                                         {
                                             Audio.Engine.Dispose();
                                         }
            };
            Window.Closed += (o, e) => IsRunning = false;

            //Get bin directory.
            var ass = Assembly.GetExecutingAssembly();

            AssPath = Path.GetDirectoryName(ass.Location);

            //Initialize Audio
            Audio.StartEngine();

            //Config
            Config.PopulateConfig(AssPath + "/Resources/Config/config.xml");

            //SpriteBatch/Atlas
            AtlasData   = new AtlasData(AssPath + "/Resources/Textures/Atlas");
            SpriteBatch = new SpriteBatch(AtlasData.AtlasTexture);

            //Container
            var moduleContainer = new ModuleContainer();

            //Modules
            LoadModules(moduleContainer);

            //Update SpriteBatch
            SpriteBatch.SortZ();
            SpriteBatch.CalculateVertices();

            //Main loop
            while (IsRunning)
            {
                Window.DispatchEvents();
                if (!WindowFocused)
                {
                    Thread.Sleep(200); //Doesn't need to run as smooth.
                }
                Window.Clear(Config.Colors["background"]);

                if ((Keyboard.IsKeyPressed(Keyboard.Key.LAlt) || Keyboard.IsKeyPressed(Keyboard.Key.RAlt)) &&
                    Keyboard.IsKeyPressed(Keyboard.Key.F4))
                {
                    IsRunning = false;
                }

                moduleContainer.Update();

                Window.Display();
            }

            Audio.Engine.Dispose();
            Window.Close();
        }