Exemple #1
0
        protected override void Initialize()
        {
            ViewPortHelper.SetViewPort(this.GraphicsDevice.Viewport.Width, this.GraphicsDevice.Viewport.Height);
            ViewPortHelper.SetWindowedSize(windowedWidth, windowedHeight);
            ViewPortHelper.GraphicsDevice        = GraphicsDevice;
            ViewPortHelper.GraphicsDeviceManager = graphics;
            ViewPortHelper.Game = this;

            // find maximum size of render field with 3:2 aspect ratio when full screen

            int width  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            int height = (int)(width / aspectRatio);

            if (height > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height)
            {
                height = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
                width  = (int)(height * aspectRatio);
            }

            float xScale = 1f;
            float yScale = 1f;

            int xOffset = (int)((GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - width) / 2.0);
            int yOffset = (int)((GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - height) / 2.0);

            ViewPortHelper.SetScreenSize(width, height);
            ViewPortHelper.SetDrawScale(xScale, yScale);
            ViewPortHelper.SetDrawOffset(xOffset, yOffset);
            ViewPortHelper.SetWindowedSize(windowedWidth, windowedHeight);

            GameStateManager.CurrentGameState = GameState.MainMenu;//GameState.MainMenu;
            GameStateManager.HasChanged       = true;

            base.Initialize();
        }
Exemple #2
0
        internal override void Update(GameTime gameTime, SpriteBatch batch)
        {
            if (InputHelper.WasButtonPressed(Microsoft.Xna.Framework.Input.Keys.Enter) || InputHelper.WasButtonPressed(Microsoft.Xna.Framework.Input.Keys.Space) || InputHelper.WasPadButtonPressedP1(Buttons.A))
            {
                if (tree == 0)
                {
                    if (selected == 0)
                    {
                        GameStateManager.CurrentGameState = GameState.InGame;
                        GameStateManager.HasChanged       = true;
                    }
                    else if (selected == 1)
                    {
                        ScoreHelper.NPlayers += 1;
                        if (ScoreHelper.NPlayers > 4)
                        {
                            ScoreHelper.NPlayers = 1;
                        }
                        if (ScoreHelper.NAIPlayers == 0 && ScoreHelper.NPlayers == 1)
                        {
                            ScoreHelper.NAIPlayers = 1;
                        }
                    }
                    else if (selected == 2)
                    {
                        ScoreHelper.NAIPlayers += 1;
                        if (ScoreHelper.NAIPlayers > 4)
                        {
                            ScoreHelper.NAIPlayers = 0;
                        }
                        if (ScoreHelper.NAIPlayers == 0 && ScoreHelper.NPlayers == 1)
                        {
                            ScoreHelper.NAIPlayers = 1;
                        }
                    }
                    else if (selected == 3)
                    {
                        ViewPortHelper.ToggleFullscreen();
                    }
                    else if (selected == 4)
                    {
                        tree     = 1;
                        selected = 0;
                    }
                    else if (selected == 5)
                    {
                        Game.Exit();
                    }
                }

                else if (tree == 1)
                {
                    if (selected == 0)
                    {
                        GameStateManager.CurrentGameState = GameState.InGame;
                        GameStateManager.HasChanged       = true;
                    }
                    else if (selected == 1)
                    {
                        GameStateManager.CurrentGameState = GameState.InGame;
                        GameStateManager.HasChanged       = true;
                    }
                    else
                    {
                        tree     = 0;
                        selected = 0;
                    }
                }
            }

            // exit game
            if (InputHelper.WasButtonPressed(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                Game.Exit();
            }

            // menu control
            if (InputHelper.WasButtonPressed(Microsoft.Xna.Framework.Input.Keys.Up) || InputHelper.WasPadThumbstickUpP1())
            {
                selected -= 1;
            }
            if (InputHelper.WasButtonPressed(Microsoft.Xna.Framework.Input.Keys.Down) || InputHelper.WasPadThumbstickDownP1())
            {
                selected += 1;
            }

            if (selected > max)
            {
                selected = 0;
            }
            if (selected < 0)
            {
                selected = max;
            }


            // toggle fullscreen

            if (InputHelper.WasButtonPressed(Microsoft.Xna.Framework.Input.Keys.F) || InputHelper.WasPadButtonPressedP1(Buttons.X))
            {
                ViewPortHelper.ToggleFullscreen();
            }

            colours = new List <Color> {
                Color.White, Color.White, Color.White, Color.White, Color.White, Color.White
            };
            colours[selected] = Color.Red;
        }