Ejemplo n.º 1
0
        public OctoGame()
        {
            //graphics = new GraphicsDeviceManager(this);
            //graphics.PreferredBackBufferWidth = 1080;
            //graphics.PreferredBackBufferHeight = 720;

            //Content.RootDirectory = "Content";
            Title = "OctoAwesome";
            IsMouseVisible = true;
            Icon = Properties.Resources.octoawesome;

            //Window.AllowUserResizing = true;
            Settings = new Settings();
            ResourceManager.Settings = Settings;

            //TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 15);

            int width = 1080, height = 720;
            if (Settings.KeyExists("Width"))
                width = Settings.Get<int>("Width");
            if (Settings.KeyExists("Height"))
               height = Settings.Get<int>("Height");
            Window.ClientSize = new Size(width, height);

            if (Settings.KeyExists("EnableFullscreen") && Settings.Get<bool>("EnableFullscreen"))
                Window.Fullscreen = true;

            if (Settings.KeyExists("Viewrange"))
            {
                var viewrange = Settings.Get<int>("Viewrange");

                if (viewrange < 1)
                    throw new NotSupportedException("Viewrange in app.config darf nicht kleiner 1 sein");

                SceneControl.VIEWRANGE = viewrange;
            }

            Assets = new AssetComponent(this);
            Components.Add(Assets);

            Simulation = new SimulationComponent(this);
            Simulation.UpdateOrder = 4;
            Components.Add(Simulation);

            Player = new PlayerComponent(this);
            Player.UpdateOrder = 2;
            Components.Add(Player);

            Camera = new CameraComponent(this);
            Camera.UpdateOrder = 3;
            Components.Add(Camera);

            Screen = new ScreenComponent(this);
            Screen.UpdateOrder = 1;
            Screen.DrawOrder = 1;
            Components.Add(Screen);

            KeyMapper = new KeyMapper(Screen, Settings);

            /*Resize += (s, e) =>
            {
                //if (Window.ClientBounds.Height == graphics.PreferredBackBufferHeight &&
                //   Window.ClientBounds.Width == graphics.PreferredBackBufferWidth)
                //    return;

                //graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
                //graphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
                //graphics.ApplyChanges();
            };*/
            SetKeyBindings();
        }
Ejemplo n.º 2
0
        public OctoGame()
            : base()
        {
            graphics = new GraphicsDeviceManager(this);

            int width;
            if (int.TryParse(SettingsManager.Get("Width"), out width))
            {
                if (width < 1)
                    throw new NotSupportedException("Width in app.config darf nicht kleiner 1 sein");

                graphics.PreferredBackBufferWidth = width;
            }
            else
                graphics.PreferredBackBufferWidth = 1080;

            int height;
            if (int.TryParse(SettingsManager.Get("Height"), out height))
            {
                if (height < 1)
                    throw new NotSupportedException("Height in app.config darf nicht kleiner 1 sein");

                graphics.PreferredBackBufferHeight = height;
            }
            else
                graphics.PreferredBackBufferHeight = 720;

            Content.RootDirectory = "Content";
            Window.Title = "OctoAwesome";
            IsMouseVisible = true;
            Window.AllowUserResizing = true;

            TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 15);

            bool enablefullscreen;
            if (bool.TryParse(SettingsManager.Get("EnableFullscreen"), out enablefullscreen) && enablefullscreen)
                Fullscreen();

            int viewrange;
            if (int.TryParse(SettingsManager.Get("Viewrange"), out viewrange))
            {
                if (viewrange < 1)
                    throw new NotSupportedException("Viewrange in app.config darf nicht kleiner 1 sein");

                SceneControl.VIEWRANGE = viewrange;
            }

            Simulation = new SimulationComponent(this);
            Simulation.UpdateOrder = 4;
            Components.Add(Simulation);

            Player = new PlayerComponent(this);
            Player.UpdateOrder = 2;
            Components.Add(Player);

            Camera = new CameraComponent(this);
            Camera.UpdateOrder = 3;
            Components.Add(Camera);

            Screen = new ScreenComponent(this);
            Screen.UpdateOrder = 1;
            Screen.DrawOrder = 1;
            Components.Add(Screen);

            KeyMapper = new KeyMapper(Screen);

            Window.ClientSizeChanged += (s, e) =>
            {
                if (Window.ClientBounds.Height == graphics.PreferredBackBufferHeight &&
                   Window.ClientBounds.Width == graphics.PreferredBackBufferWidth)
                    return;

                graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
                graphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
                graphics.ApplyChanges();
            };

            SetKeyBindings();
        }