Update() public méthode

Updates the GameObjectManager, and all objects in the game
public Update ( float elapsedTime ) : void
elapsedTime float The time between this and the previous frame
Résultat void
Exemple #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();
            }

            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            // Update according to current game state
            switch (GameState)
            {
            case GameState.Initializing:
                if (!LevelManager.Loading)
                {
                    GameState = GameState.Gameplay;
                }
                break;

            case GameState.Splash:

                if (!LevelManager.Loading && Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    GameState = GameState.Gameplay;
                    Music     = LevelManager.CurrentSong;
                    if (Music != null)
                    {
                        MediaPlayer.Play(Music);
                    }
                }
                break;

            case GameState.Gameplay:
                LevelManager.Update(elapsedTime);
                GameObjectManager.Update(elapsedTime);
                ProcessCollisions();
                break;

            case GameState.Scoring:
                if (!GuiManager.Tallying && Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    GameState = GameState.Splash;
                    Music     = Splash.Music;
                    if (Music != null)
                    {
                        MediaPlayer.Play(Music);
                    }
                }
                break;

            case GameState.Credits:
                // TODO: Launch new game when player hits space
                break;
            }

            base.Update(gameTime);
        }
        /// <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();
            }

            // TODO: Add your update logic here
            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            LevelManager.Update(elapsedTime);

            GameObjectManager.Update(elapsedTime);

            // Process collisions
            foreach (CollisionPair pair in GameObjectManager.Collisions)
            {
                // Player collisions
                if (pair.A == Player.ID || pair.B == Player.ID)
                {
                    uint       colliderID = (pair.A == Player.ID) ? pair.B : pair.A;
                    GameObject collider   = GameObjectManager.GetObject(colliderID);

                    // Process powerup collisions
                    Powerup powerup = collider as Powerup;
                    if (powerup != null)
                    {
                        Player.ApplyPowerup(powerup.Type);
                        GameObjectManager.DestroyObject(colliderID);
                    }

                    //NOTE: Apply to more than the kamikaze enemy?
                    // Process kamakaze collisions
                    Enemy enemy = collider as Enemy;
                    if (enemy != null && enemy.GetType() == typeof(Kamikaze))
                    {
                        //Player take damage
                        GameObjectManager.DestroyObject(colliderID);
                        GameObjectManager.CreateExplosion(colliderID);
                    }
                }
            }

            base.Update(gameTime);
        }