Ejemplo 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)
        {
            kState = Keyboard.GetState(); //first thing
            mState = Mouse.GetState();    //second thing

            player.worldEnemies = worldEnemies;

            if (currentState == GameState.Game)                                      //if in game
            {
                if (kState.IsKeyDown(Keys.Escape) && oldKState.IsKeyUp(Keys.Escape)) //escape is pressed
                {
                    currentState = GameState.Pause;                                  // go to pause menu
                }
                player.Physics();
                player.Movement(gameTime); // threw in gametime for animation
                player.Attack();
                Tuple <bool, Rectangle> test = player.Test();
                if (test.Item1)
                {
                    heart = new Heart(spriteSheet, test.Item2, player);
                }
                gen.Update(gameTime);

                //rangedEnemy.Update(gameTime);
                //rangedEnemy.Attack();
                //meleeEnemy.Update(gameTime);
                //meleeEnemy.Attack();

                // Update enemies
                foreach (List <Enemy> enemies in worldEnemies.Values)
                {
                    for (int i = 0; i < enemies.Count; i++)
                    {
                        enemies[i].Update(gameTime);
                        enemies[i].Attack();
                    }
                }

                if (player.IsActive == false)
                {
                    currentState = GameState.GameOver;
                }
            }
            else if (currentState == GameState.Pause || currentState == GameState.Menu || currentState == GameState.GameOver) //if in pause menu/start menu
            {
                menu.Input();                                                                                                 //check for menu input
                if (kState.IsKeyDown(Keys.Escape) && oldKState.IsKeyUp(Keys.Escape))                                          //if escape is pressed
                {
                    currentState = GameState.Game;                                                                            //exit the menu
                }
            }
            //added the ability to exit the score screen with esc or backspace
            if (currentState == GameState.ScoreScreen)
            {
                if (kState.IsKeyDown(Keys.Escape) || kState.IsKeyDown(Keys.Back))
                {
                    currentState = GameState.Menu;
                }
            }

            if (kState.IsKeyDown(Keys.Enter))          //if enter is pressed
            {
                if (currentState == GameState.Pause)   // If pause menu
                {
                    switch (menu.SelectionIndex)       //check what is currently selected
                    {
                    case 0:                            //if the top button, play/resume game, is selected
                        currentState = GameState.Game; //unpause game
                        //firstMenu = false;//no longer first menu, if not already
                        break;

                    case 1:    //if restart is selected
                        Initialize();
                        currentState = GameState.Game;
                        break;

                    case 2:     //if exit game is selected
                        Exit(); //close the game
                        break;  //do nothing
                    }
                }
                else if (currentState == GameState.Menu) // If main menu
                {
                    switch (menu.SelectionIndex)         //check what is currently selected
                    {
                    case 0:                              //if the top button, play game is selected
                        currentState = GameState.Game;   //unpause game
                        break;

                    case 1:    //selects the score menu
                        currentState = GameState.ScoreScreen;
                        //Console.WriteLine("Setting to pause menu");
                        break;  //do nothing

                    case 2:     //if exit game is selected
                        Exit(); //close the game
                        break;
                    }
                }
                else if (currentState == GameState.GameOver) // If GameOver screen
                {
                    switch (menu.SelectionIndex)             //check what is currently selected
                    {
                    case 0:                                  //selects restart
                        Initialize();
                        currentState = GameState.Game;
                        break;

                    case 1:    //selects the score menu
                        currentState = GameState.ScoreScreen;
                        //Console.WriteLine("Setting to pause menu");
                        break;    //do nothing

                    case 2:
                        //if exit game is selected
                        Exit();    //close the game
                        break;
                    }
                }
            }


            cameraPos = new Vector3((player.CharacterBox.X * -1) + playerXCamera, 0, 0f);
            //last thing
            oldKState = kState;
            base.Update(gameTime);
        }