Exemplo n.º 1
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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                gameState = GameState.StartMenu;

            // TODO: Add your update logic here
            if (gameState == GameState.StartMenu)
            {
                if (LoadedGameState != GameState.StartMenu)
                {
                    Content.Unload();
                    startMenu = new StartMenuScreen(graphics);
                    startMenu.Initialize();
                    startMenu.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.StartMenu;
                }
                startMenu.Update(gameTime);
            }

            if (gameState == GameState.OptionsMenu)
            {
                if (LoadedGameState != GameState.OptionsMenu)
                {
                    Content.Unload();
                    optionsMenuScreen = new OptionsMenuScreen();
                    optionsMenuScreen.Initialize();
                    optionsMenuScreen.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.OptionsMenu;
                }
                optionsMenuScreen.Update(gameTime);
            }

            if (gameState == GameState.Playing)
            {
                if (LoadedGameState != GameState.Playing)
                {
                    Content.Unload();
                    gameScreen = new GameScreen(graphics);
                    gameScreen.Initialize(Content, GraphicsDevice);
                    gameScreen.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.Playing;
                }
                gameScreen.Update(gameTime, GraphicsDevice);
            }

            // Gameover goes to Start Menu for now
            if (gameState == GameState.GameOver)
            {
                gameState = GameState.StartMenu;
                if (LoadedGameState != GameState.StartMenu)
                {
                    Content.Unload();
                    startMenu = new StartMenuScreen(graphics);
                    startMenu.Initialize();
                    startMenu.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.StartMenu;
                }
                startMenu.Update(gameTime);
            }

            if (gameState == GameState.Exiting)
                this.Exit();

            base.Update(gameTime);
        }
Exemplo n.º 2
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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                gameState = GameState.StartMenu;
            }

            // TODO: Add your update logic here
            if (gameState == GameState.StartMenu)
            {
                if (LoadedGameState != GameState.StartMenu)
                {
                    Content.Unload();
                    startMenu = new StartMenuScreen(graphics);
                    startMenu.Initialize();
                    startMenu.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.StartMenu;
                }
                startMenu.Update(gameTime);
            }

            if (gameState == GameState.OptionsMenu)
            {
                if (LoadedGameState != GameState.OptionsMenu)
                {
                    Content.Unload();
                    optionsMenuScreen = new OptionsMenuScreen();
                    optionsMenuScreen.Initialize();
                    optionsMenuScreen.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.OptionsMenu;
                }
                optionsMenuScreen.Update(gameTime);
            }

            if (gameState == GameState.Playing)
            {
                if (LoadedGameState != GameState.Playing)
                {
                    Content.Unload();
                    gameScreen = new GameScreen(graphics);
                    gameScreen.Initialize(Content, GraphicsDevice);
                    gameScreen.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.Playing;
                }
                gameScreen.Update(gameTime, GraphicsDevice);
            }

            // Gameover goes to Start Menu for now
            if (gameState == GameState.GameOver)
            {
                gameState = GameState.StartMenu;
                if (LoadedGameState != GameState.StartMenu)
                {
                    Content.Unload();
                    startMenu = new StartMenuScreen(graphics);
                    startMenu.Initialize();
                    startMenu.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.StartMenu;
                }
                startMenu.Update(gameTime);
            }

            if (gameState == GameState.Exiting)
            {
                this.Exit();
            }

            base.Update(gameTime);
        }