ScrollingShooter.GameObjectManager.Update C# (CSharp) Method

Update() public method

Updates the GameObjectManager, and all objects in the game
public Update ( float elapsedTime ) : void
elapsedTime float The time between this and the previous frame
return void
        public void Update(float elapsedTime)
        {
            // Add newly created game objects
            while (createdGameObjects.Count > 0)
            {
                GameObject go = createdGameObjects.Dequeue();
                if (go is Enemy || go is Boss || go is Powerup) scrollingObjects.Add(go.ID);
                else if (go is Projectile) projectileObjects.Add(go.ID);
                AddGameObject(go);
            }

            // Remove destroyed game objects
            while (destroyedGameObjects.Count > 0)
            {
                GameObject go = destroyedGameObjects.Dequeue();
                if (go is Enemy || go is Boss || go is Powerup) scrollingObjects.Remove(go.ID);
                else if (go is Projectile) projectileObjects.Remove(go.ID);
                RemoveGameObject(go);
            }

            // Update our axis lists
            UpdateAxisLists();
        }

Usage Example

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

            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);
        }
All Usage Examples Of ScrollingShooter.GameObjectManager::Update