/// <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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            consys.UpdateStates();
            manager.soundsys.Update(mainMenu, currentStage);
            if (realDead)
            {
                int temp = consys.UpdateEndScreen(manager);
                if (temp > -1)
                {
                    manager.soundsys.stopSong();
                    manager.soundsys.playMenuSong();
                    mainMenu = true;
                    realDead = false;
                }
            }
            else if (loading)
            {
                if (loadTimer <= 0)
                {
                    loading = false;
                }
                loadTimer -= 1;
            }
            else if (mainMenu)
            {
                int temp = consys.UpdateMenu(manager);
                if (temp > -1)
                {
                    mainMenu = false;
                    LoadStage(temp);
                    manager.soundsys.playGameSong(currentStage);
                }
            }
            else if (victory)
            {
                int temp = consys.UpdateEndScreen(manager);
                if (temp > -1)
                {
                    manager.soundsys.stopSong();
                    manager.soundsys.playMenuSong();
                    mainMenu = true;
                    victory  = false;
                }
            }
            else
            {
                if (consys.checkReset())
                {
                    dead   = false;
                    paused = false;
                    int temp = manager.currentLives();
                    LoadStage(currentStage);
                    manager.soundsys.playGameSong(currentStage);
                    manager.persistLives(temp);
                }
                if (!paused && !dead)
                {
                    consys.Update(manager);
                    projsys.Update(manager, GraphicsDevice);
                    pathsys.Update(manager);
                    int lives;
                    switch (colsys.Update(manager, GraphicsDevice))
                    {
                    case 1:
                        if (currentStage < manager.numStages - 1)     // load next stage
                        {
                            lives         = manager.currentLives();
                            currentStage += 1;
                            if (((currentStage - 1) / 3) < ((currentStage) / 3))
                            {
                                manager.soundsys.playGameSong(currentStage + 1);
                            }
                            LoadStage(currentStage);
                            manager.persistLives(lives);
                            break;
                        }
                        else     // load victory screen
                        {
                            manager.clearDictionaries();
                            LoadMainMenu();
                            victory = true;
                            manager.soundsys.playVictorySong();
                            break;
                        }

                    case -1:
                        break;

                    default:
                        lives = manager.currentLives();
                        if (lives == 0)     //add death screen here later
                        {
                            realDead = true;
                            manager.clearDictionaries();
                            LoadMainMenu();
                            manager.soundsys.playDeathSong();

                            break;
                        }
                        else
                        {
                            dead = true;
                            manager.soundsys.playDeathSong();
                            LoadStage(currentStage);
                            manager.persistLives(lives);
                            break;
                        }
                    }
                }
                switch (consys.checkPause())
                {
                case 1:
                    paused = !paused;
                    break;

                case 0:
                    if (paused)
                    {
                        manager.soundsys.stopSong();
                        manager.soundsys.playMenuSong();
                        manager.clearDictionaries();
                        LoadMainMenu();
                        mainMenu = true;
                        paused   = false;
                    }
                    break;

                default:
                    break;
                }
            }
            base.Update(gameTime);
        }
Пример #2
0
        public static void UpdateWorld()
        {
            ParticleSystem.Update();
            //ParticleSystem.Update();
            Weather.Update();

            if (TMBAW_Game.CurrentGameMode == GameMode.Edit)
            {
                foreach (Player player in GetPlayers())
                {
                    player.ComplexAnimation.RemoveAllFromQueue();
                    player.AddAnimationToQueue("editMode");
                }
                LevelEditor.Update();
            }
            else
            {
                if (IsTestingLevel)
                {
                    if (GetPlayers()[0].IsTestLevelPressed())
                    {
                        LevelEditor.GoBackToEditing();
                    }
                }
                UpdateVisual();
            }

            TimesUpdated++;

            ProjectileSystem.Update();

            for (var i = Entities.Count - 1; i >= 0; i--)
            {
                var entity = Entities[i];
                if (entity.ToDelete)
                {
                    entity.Destroy();
                }
            }
            foreach (Player player in GetPlayers())
            {
                player.Update();
            }

            if (TMBAW_Game.CurrentGameMode == GameMode.Play)
            {
                foreach (Player player in GameWorld.GetPlayers())
                {
                    PlayerTrail.Add(player);
                }
            }

            foreach (var c in _clouds)
            {
                c.CheckOutOfRange();
                c.Update();
            }
            for (var i = 0; i < Entities.Count; i++)
            {
                var entity = Entities[i];
                if (entity.IsDead)
                {
                    continue;
                }
                entity.Update();

                //// Check enemy collision with other enemies.
                //for (int j = i + 1; j < Entities.Count; j++)
                //{
                //    if (Entities[i].IsTouchingEntity(Entities[j]))
                //    {
                //        if (Entities[i].Position.X > Entities[j].Position.X)
                //        {
                //            Entities[i].SetX(Entities[j].Position.X + Entities[j].CollRectangle.Width / 2);
                //        }
                //        else
                //        {
                //            Entities[i].SetX(Entities[j].Position.X - Entities[i].CollRectangle.Width / 2);
                //        }
                //        Entities[i].ForceUpdateCollisionRectangle();
                //    }
                //}
            }


            foreach (var tileNumber in ChunkManager.GetVisibleIndexes())
            {
                if (tileNumber >= 0 && tileNumber < TileArray.Length)
                {
                    TileArray[tileNumber]?.Update();
                }
            }

            if (Session.IsHost)
            {
                Session.SendEntityUpdates();
            }
        }