Exemple #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()
        {
            // TODO: Add your initialization logic here
            gameState       = GameState.StartMenu;
            LoadedGameState = GameState.StartMenu;
            startMenu       = new StartMenuScreen(graphics);
            startMenu.Initialize();

            base.Initialize();
        }
Exemple #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)
        {
#if (ANDROID)
            // Get touch input
            bool gesturing = false;
            while (TouchPanel.IsGestureAvailable)
            {
                gesture   = TouchPanel.ReadGesture();
                gesturing = true;
            }

            // Start the game
            if (gesture.GestureType == GestureType.Tap)
            {
                gameState = GameState.Playing;
            }
#endif
            CurrentKeyboardState = Keyboard.GetState();
            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 (CurrentKeyboardState.IsKeyUp(Keys.P) && PreviousKeyboardState.IsKeyDown(Keys.P))
            {
                if (gameState == GameState.Paused)
                {
                    gameState = GameState.Playing;
                }
                else if (gameState == GameState.Playing)
                {
                    gameState = GameState.Paused;
                }
            }

            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)
            {
                if (LoadedGameState != GameState.GameOver)
                {
                    Content.Unload();
                    gameOverScreen = new GameOverScreen();
                    gameOverScreen.Initialize();
                    gameOverScreen.LoadContent(Content, GraphicsDevice);
                    LoadedGameState = GameState.GameOver;
                }
                gameOverScreen.Update(gameTime, GraphicsDevice);
            }

#if (ANDROID)
            if (gesturing == false)
            {
                gesture = new GestureSample();
            }
#endif

            if (gameState == GameState.Exiting)
            {
                this.Exit();
            }
            PreviousKeyboardState = Keyboard.GetState();
            base.Update(gameTime);
        }