Esempio 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)
        {
            currentState = Keyboard.GetState();

            //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            //    Exit();

            if (mainMenu != null)
            {
                if (mainMenu.isActive)
                {
                    UpdateMainMenu(gameTime);
                }
            }

            if (level != null)
            {
                if (!gamePaused && level.isActive)
                {
                    UpdateLevel(gameTime);
                }
            }

            if (endgame != null)
            {
                if (endgame.isActive)
                {
                    endgame.Update(gameTime, this);
                }
            }

            if (InputManager.CheckInputKeyboard(oldState, currentState, Keys.Escape) && !gamePaused && level.isActive)
            {
                gamePaused = true;
            }

            else if (InputManager.CheckInputKeyboard(oldState, currentState, Keys.Escape) && gamePaused && level.isActive)
            {
                gamePaused = false;
            }

            if (gamePaused)
            {
                UpdatePauseMenu(gameTime);
            }


            if (playerIsDead && endgame == null)
            {
                level            = null;
                endgame          = new EndGameScreen(endGameBackground, mainMenuButton, mainMenuQuitButton);
                endgame.isActive = true;
            }

            oldState = currentState;

            base.Update(gameTime);
        }
Esempio n. 2
0
 /// <summary>
 /// Load level and their contents
 /// </summary>
 /// <param name="i"></param>
 public void LoadLevel(int i)
 {
     if (i == 1)
     {
         level = new Level(Level.MapState.map1, GraphicsDevice, this);
     }
     else if (i == 2)
     {
         level = new Level(Level.MapState.map2, GraphicsDevice, this);
     }
     else if (i == 3)
     {
         level = new Level(Level.MapState.map3, GraphicsDevice, this);
     }
     else if (i > 3)
     {
         level            = null;
         endgame          = new EndGameScreen(endGameBackground, mainMenuButton, mainMenuQuitButton);
         endgame.isActive = true;
     }
 }
Esempio n. 3
0
 public void SetMainMenuActive(bool isActive)
 {
     if (isActive)
     {
         if (level != null)
         {
             level.isActive = false;
             level          = null;
             gamePaused     = false;
         }
         if (endgame != null)
         {
             endgame.isActive = false;
             endgame          = null;
             playerIsDead     = false;
         }
         if (mainMenu == null)
         {
             mainMenu = new MainMenu(mainMenuBackground, mainMenuStartButton, mainMenuQuitButton);
         }
         mainMenu.isActive = true;
     }
 }