Blink.StateGame.Update C# (CSharp) Method

Update() public method

public Update ( GameTime gameTime ) : void
gameTime Microsoft.Xna.Framework.GameTime
return void
        public void Update(GameTime gameTime)
        {
            KeyboardState currState = Keyboard.GetState();

            if(paused)
            {
                if (currState.IsKeyDown(Keys.P) && currState != oldState && playerPaused == (int)currPlayer)
                {
                    paused = false;
                    oldState = currState;
                }
                foreach (PlayerIndex x in Enum.GetValues(typeof(PlayerIndex)))
                {
                    if (playerPaused == (int)x && GamePad.GetState(x).IsButtonDown(Buttons.Start) && !oldStartState[(int)x])
                    {
                        paused = false;
                        oldStartState[(int)x] = GamePad.GetState(x).IsButtonDown(Buttons.Start);
                    }
                }
            }

            if (!paused)
            {
                if (currState.IsKeyDown(Keys.P) && currState != oldState)
                {
                    paused = true;
                    oldState = currState;
                    playerPaused = (int)currPlayer;
                }
                foreach (PlayerIndex x in Enum.GetValues(typeof(PlayerIndex)))
                {
                    if (GamePad.GetState(x).IsButtonDown(Buttons.Start) && !oldStartState[(int)x])
                    {
                        paused = true;
                        playerPaused = (int)x;
                    }
                }
            }

            if (paused)
            {
                oldState = currState;
                oldStartState[0] = GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start);
                oldStartState[1] = GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Start);
                oldStartState[2] = GamePad.GetState(PlayerIndex.Three).IsButtonDown(Buttons.Start);
                oldStartState[3] = GamePad.GetState(PlayerIndex.Four).IsButtonDown(Buttons.Start);

                GamePadState p1 = GamePad.GetState(PlayerIndex.One);
                if (p1.IsButtonDown(Buttons.LeftTrigger) && p1.IsButtonDown(Buttons.RightTrigger) && p1.IsButtonDown(Buttons.LeftShoulder) && p1.IsButtonDown(Buttons.RightShoulder))
                    returnState = levelSelect;
                GamePadState p2 = GamePad.GetState(PlayerIndex.Two);
                if (p2.IsButtonDown(Buttons.LeftTrigger) && p2.IsButtonDown(Buttons.RightTrigger) && p2.IsButtonDown(Buttons.LeftShoulder) && p2.IsButtonDown(Buttons.RightShoulder))
                    returnState = levelSelect;
                GamePadState p3 = GamePad.GetState(PlayerIndex.Three);
                if (p3.IsButtonDown(Buttons.LeftTrigger) && p3.IsButtonDown(Buttons.RightTrigger) && p3.IsButtonDown(Buttons.LeftShoulder) && p3.IsButtonDown(Buttons.RightShoulder))
                    returnState = levelSelect;
                GamePadState p4 = GamePad.GetState(PlayerIndex.Four);
                if (p4.IsButtonDown(Buttons.LeftTrigger) && p4.IsButtonDown(Buttons.RightTrigger) && p4.IsButtonDown(Buttons.LeftShoulder) && p4.IsButtonDown(Buttons.RightShoulder))
                    returnState = levelSelect;
                if (Keyboard.GetState().IsKeyDown(Keys.R))
                    returnState = levelSelect;
                return;
            }

            /* Press TAB to change player if using keyboard. *** For Testing Purposes Only ***
                If you hold down a key while pressing TAB, the previous player will continue to do that same action
                over and over again until you tab to that player again.
                (It is kinda amusing, but could be useful for collison testing) */
            if (currState.IsKeyDown(Keys.Tab) && oldState != currState)
            {
                switch ((int)currPlayer)
                {
                    case 0:
                        currPlayer = PlayerKeys.Player2;
                        break;

                    case 1:
                        currPlayer = PlayerKeys.Player3;
                        break;

                    case 2:
                        currPlayer = PlayerKeys.Player4;
                        break;

                    case 3:
                        currPlayer = PlayerKeys.allPlayers;
                        break;

                    case 4:
                        currPlayer = PlayerKeys.Player1;
                        break;
                }
                //Switches to the next player
            }
            if (currPlayer == PlayerKeys.Player1)
            {
                player1State = Keyboard.GetState();
            }

            if (currPlayer == PlayerKeys.Player2)
            {
                player2State = Keyboard.GetState();
            }

            if (currPlayer == PlayerKeys.Player3)
            {
                player3State = Keyboard.GetState();
            }
            if (currPlayer == PlayerKeys.Player4)
            {
                player4State = Keyboard.GetState();
            }

            if (currPlayer == PlayerKeys.allPlayers)
            {
                player1State = Keyboard.GetState();
                player2State = Keyboard.GetState();
                player3State = Keyboard.GetState();
                player4State = Keyboard.GetState();
            }
            //End of TAB code. Can now only control one player at a time using keyboard.
            player1.Update(player1State, GamePad.GetState(PlayerIndex.One), gameTime);
            player2.Update(player2State, GamePad.GetState(PlayerIndex.Two), gameTime);
            player3.Update(player3State, GamePad.GetState(PlayerIndex.Three), gameTime);
            player4.Update(player4State, GamePad.GetState(PlayerIndex.Four), gameTime);
            foreach (SpearClass sp in spears)
            {

                    if (sp.spearOwner == player1)
                    {
                        sp.Update(player1State, GamePad.GetState(PlayerIndex.One));
                    }

                    else if (sp.spearOwner == player2)
                    {
                        sp.Update(player2State, GamePad.GetState(PlayerIndex.Two));
                    }
                    else if (sp.spearOwner == player3)
                    {
                        sp.Update(player3State, GamePad.GetState(PlayerIndex.Three));
                    }
                    else if (sp.spearOwner == player4)
                    {
                        sp.Update(player4State, GamePad.GetState(PlayerIndex.Four));
                    }
                    else
                    {
                        KeyboardState fakestate = new KeyboardState();
                        GamePadState faker = new GamePadState();
                        sp.Update(fakestate, faker);
                    }
            }
            oldState = currState;

            oldStartState[0] = GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start);
            oldStartState[1] = GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Start);
            oldStartState[2] = GamePad.GetState(PlayerIndex.Three).IsButtonDown(Buttons.Start);
            oldStartState[3] = GamePad.GetState(PlayerIndex.Four).IsButtonDown(Buttons.Start);
            //If a timer is running, decrement here

            timeElapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
            if(roundReset > 0)
            {
                roundReset -= timeElapsed;
                if(roundReset < 0)
                {
                    if (ultimateWin > 0)
                    {
                        returnState = Win;
                        return;
                    }
                    else
                    {
                    resetMap();
                }
            }
            }

            //Update animations
            for (int i = 0; i < animations.Count; i++)
            {
                animations[i].Update(gameTime);
            }
        }