Esempio n. 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
#if DEBUG
            this.Window.Title = "Asteroids-dev-debug";
#else
            this.Window.Title = "Asteroids-dev-release";
#endif
            this.Window.Title += " - Version: " + this.GetVersionString();
            System.Diagnostics.Trace.WriteLine(DateTime.Now + " " + this.Window.Title);

            UserConfig.Instance = UserConfig.Load();

            WindowSettings.Initialize(this, this.graphics);
            WindowSettings.SetWindowResolution(new Point(UserConfig.Instance.ScreenWidth, UserConfig.Instance.ScreenHeight));
            WindowSettings.SetBorderless(UserConfig.Instance.Borderless);
            WindowSettings.MinWindowResolution = GameConfig.MinWindowSize;
            WindowSettings.UnitsVisible        = new Vector2(1280, 720);

            this.renderTarget = new RenderTarget2D(this.GraphicsDevice, WindowSettings.RenderArea.Width, WindowSettings.RenderArea.Height);

            this.sceneManager = new GUISceneManager(this);

            this.Components.Add(new Kadro.Input.KeyboardInput(this));
            this.Components.Add(new MouseInput(this));
            this.Components.Add(new GamepadInput(this));
            this.Components.Add(new TouchpanelInput(this));
            this.performanceCounter = new PerformanceMetrics();

            Assets.Initialize(Content);

            this.networkManager = new NetworkManager(UserConfig.Instance.NetworkName);
            this.connectionInfo = new BaseConnection();

            base.Initialize();
        }
Esempio n. 2
0
        private void ApplyChanges()
        {
            //TODO: when switching out of borderless and simultaneously changing resolution, the previous bordered resolution is used
            // instead of the new one, workaround is to apply again
            WindowSettings.SetWindowResolution(this.tempResolution);
            WindowSettings.SetBorderless(this.borderlessCheck.IsChecked);

            UserConfig.Instance.Borderless   = this.borderlessCheck.IsChecked;
            UserConfig.Instance.ScreenWidth  = this.tempResolution.X;
            UserConfig.Instance.ScreenHeight = this.tempResolution.Y;
            UserConfig.Instance.Save();

            this.unsavedChanges = false;
            this.unsavedChangesText.SetVisible(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            ////if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            ////    Exit();

            this.performanceCounter.BeginUpdate();

            base.Update(gameTime);

            this.performanceCounter.Update(gameTime);

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.F12))
            {
                WindowSettings.SetBorderless(this.isBorderless = !this.isBorderless);
            }

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.Up) || Kadro.Input.KeyboardInput.OnKeyUp(Keys.Left))
            {
                this.sceneManager.TabPrevious();
            }

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.Down) || Kadro.Input.KeyboardInput.OnKeyUp(Keys.Right))
            {
                this.sceneManager.TabNext();
            }

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.F3))
            {
                this.showPerformanceStats = !this.showPerformanceStats;
            }

            if (!(this.renderTarget.Width == WindowSettings.RenderArea.Width && this.renderTarget.Height == WindowSettings.RenderArea.Height))
            {
                this.renderTarget.Dispose();
                this.renderTarget = new RenderTarget2D(this.GraphicsDevice, WindowSettings.RenderArea.Width, WindowSettings.RenderArea.Height);
            }

            this.sceneManager.Update(gameTime);
            this.perfLabel.Update();
#if DEBUG
            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.F1))
            {
                if (this.debugListbox.IsVisible)
                {
                    this.debugListbox.Hide();
                }
                else
                {
                    this.debugListbox.Show();
                }
            }

            this.debugListbox.Update();

            Point   cursor   = MouseInput.GetCursorPosition();
            Vector2 viewPos  = WindowSettings.ScreenToView(cursor.ToVector2());
            Vector2 worldPos = GameScene.ActiveScene.ViewToWorld(viewPos);
            this.mousePos.TextBlock.Text = $"MousePos: {cursor}\nViewPos: {viewPos}\nWorldPos: {worldPos}";

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.F5))
            {
                if (this.mousePos.IsVisible)
                {
                    this.mousePos.SetVisible(false);
                }
                else
                {
                    this.mousePos.SetVisible(true);
                }
            }

            if (Kadro.Input.KeyboardInput.OnKeyUp(Keys.L) && this.networkManager.IsActive)
            {
                this.networkManager.SetDebugLatency(0.05f, 0.02f, 0.0f);  // 50ms, 20ms
                this.networkManager.EnableDebugLatency(!this.networkManager.DebugLatency);
            }
#endif
            GameScene.ActiveScene.Update(gameTime);

            this.performanceCounter.EndUpdate();

            if (this.showPerformanceStats)
            {
                this.ShowPerformanceOnWindowTitle();
            }
        }