コード例 #1
0
        protected override void Update(GameTime gameTime)
        {
            keyControl.Update();

            //Update main menu HUD only if we haven't selected game type
            if (!gameTypeSelected)
            {
                if (MainMenuHUD != null)
                {
                    MainMenuHUD.Update();
                }
                return;
            }

            //If game is paused, exit.
            if (paused)
            {
                return;
            }

            if (levelHUD != null)
            {
                levelHUD.Update();
            }

            foreach (IPlayer player in players)
            {
                if (player != null)
                {
                    player.isCollideGround = false;
                }
            }

            CollisionDetection.Update(players.AsReadOnly(), enemies.AsReadOnly(), tiles.AsReadOnly(), items.AsReadOnly(), projectiles.AsReadOnly());

            if (levelBackground != null)
            {
                levelBackground.Update(gameTime, Zero, Zero);
            }

            foreach (ITile tile in tiles)
            {
                if (tile == null)
                {
                    continue;
                }

                if (!(tile is InvisibleItemBlockTile) && !(tile is QuestionBlockTile) && !(tile is BreakableBrickTile))
                {
                    tile.Update(gameTime);
                }
                //If the tile is an invisible block, then use a different update method.
                else
                {
                    foreach (IPlayer player in players)
                    {
                        if (player == null)
                        {
                            continue;
                        }

                        if (tile is InvisibleItemBlockTile)
                        {
                            ((InvisibleItemBlockTile)tile).Update(player, gameTime);
                        }
                        else if (tile is QuestionBlockTile)
                        {
                            ((QuestionBlockTile)tile).Update(player, gameTime);
                        }
                        else if (tile is BreakableBrickTile)
                        {
                            ((BreakableBrickTile)tile).Update(player, gameTime);
                        }
                    }
                }
            }
            foreach (IProjectile projectile in projectiles)
            {
                if (projectile != null)
                {
                    projectile.Update(gameTime);
                }
            }
            foreach (IEnemy enemy in enemies)
            {
                if (enemy != null)
                {
                    //If this is moving enemy, set isSeen field
                    if (enemy is MovingEnemy)
                    {
                        ((MovingEnemy)enemy).isSeen = mainCamera.CanSeeCollider(enemy);
                    }

                    enemy.Update(gameTime);
                }
            }
            foreach (IItem item in items)
            {
                if (item != null)
                {
                    item.Update(gameTime);
                }
            }
            foreach (IPlayer player in players)
            {
                if (player.IsDead)
                {
                    foreach (IPlayer p in players)
                    {
                        p.RestrictMovement = true;
                    }
                }
                if (player != null)
                {
                    player.Update(gameTime);
                }
            }

            bool anyDead = players != null && players.Find(o => o is Mario && ((Mario)o).IsDead) != null;

            if (mainCamera != null && !anyDead && !warping)
            {
                mainCamera.Update(players, screenWidth, screenHeight);
            }

            base.Update(gameTime);
        }