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();
            }

            Sound.Update(gameTime);

            if (inMenu)
            {
                menu.Update(gameTime);
            }
            else if (gameOver || wonLevel)
            {
                if (elapsedDelay > inputLag)
                {
                    if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start))
                    {
                        gameOver = false;
                        wonLevel = false;
                        menu.setMenuOptions(false);
                        inMenu       = true;
                        elapsedDelay = 0;
                    }
                }
                else
                {
                    elapsedDelay += gameTime.ElapsedGameTime.Milliseconds;
                }
            }
            else
            {
                if (elapsedDelay > inputLag)
                {
                    if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start))
                    {
                        inMenu       = true;
                        elapsedDelay = 0;
                    }
                }
                else
                {
                    elapsedDelay += gameTime.ElapsedGameTime.Milliseconds;
                }

                characterManager.Update(gameTime);
                levelManager.Update(gameTime);
                managedEntities.Update(gameTime);
            }

            ControllerManager.Update(gameTime);

            base.Update(gameTime);
        }
Exemplo n.º 2
0
        public void Update(GameTime gameTime)
        {
            foreach (Character c in charactersToKill)
            {
                liveCharacters.Remove(c);
                if (liveCharacters.Count == 0)
                {
                    Game1.gameOver = true; //End game
                }
            }
            if (!Multiplayer)
            {
                GamePadState gamepad    = GamePad.GetState(PlayerIndex.One);
                Vector2      leftStick  = gamepad.ThumbSticks.Left;
                Vector2      rightStick = gamepad.ThumbSticks.Right;

                if (gamepad.Buttons.LeftShoulder == ButtonState.Pressed && playerCharacters[0].alive)
                {
                    if (!playerCharacters[0].isControlled())
                    {
                        playerCharacters[0].initiateControl();
                    }
                }
                else
                {
                    if (playerCharacters[0].isControlled())
                    {
                        playerCharacters[0].releaseControl();
                    }
                }

                if (gamepad.Buttons.RightShoulder == ButtonState.Pressed && playerCharacters[1].alive)
                {
                    if (!playerCharacters[1].isControlled())
                    {
                        playerCharacters[1].initiateControl();
                    }
                }
                else
                {
                    if (playerCharacters[1].isControlled())
                    {
                        playerCharacters[1].releaseControl();
                    }
                }

                if (gamepad.Triggers.Left > .7 && playerCharacters[2].alive)
                {
                    if (!playerCharacters[2].isControlled())
                    {
                        playerCharacters[2].initiateControl();
                    }
                }
                else
                {
                    if (playerCharacters[2].isControlled())
                    {
                        playerCharacters[2].releaseControl();
                    }
                }

                if (gamepad.Triggers.Right > .7 && playerCharacters[3].alive)
                {
                    if (!playerCharacters[3].isControlled())
                    {
                        playerCharacters[3].initiateControl();
                    }
                }
                else
                {
                    if (playerCharacters[3].isControlled())
                    {
                        playerCharacters[3].releaseControl();
                    }
                }

                Vector2 movement      = new Vector2(leftStick.X, -leftStick.Y);
                Vector2 rightMovement = new Vector2(rightStick.X, -rightStick.Y);
                if (movement.Length() > 0.001f)
                {
                    applyGlobalCharacterAction(delegate(Character c)
                    {
                        c.attemptMove(Vector2.Zero);
                    });
                    applyCharacterAction(delegate(Character c)
                    {
                        c.attemptMove(movement);
                    });
                }
                else
                {
                    applyGlobalCharacterAction(delegate(Character c)
                    {
                        c.attemptMove(rightMovement);
                    });
                }
            }
            else
            {
                for (int i = 0; i < playerCharacters.Count; i++)
                {
                    GamePadState gamepad   = GamePad.GetState(ControllerManager.indexFromNumber(i));
                    Vector2      leftStick = gamepad.ThumbSticks.Left;
                    Vector2      movement  = new Vector2(leftStick.X, -leftStick.Y);
                    playerCharacters[i].attemptMove(movement);
                }
            }


            applyGlobalCharacterAction(delegate(Character c)
            {
                c.Update(gameTime);
            });
        }