예제 #1
0
        public void Update(GameTime gameTime)
        {
            if (GameData.inGameState != InGameState.Paused)
            {
                KeyboardState key = Keyboard.GetState();
                if (key.IsKeyDown(Keys.P))
                {
                    UI.enableDeveloperStats = true;
                }

                UI.Update(gameTime);
                UI.upgradeButton.Visible(false);
                bool isPlayerAboveHelipad = PlayerAboveHelipad();
                player.PlayerCanLand(isPlayerAboveHelipad);
                if (completed)
                {
                    UI.EnableTextOnScreen(100);
                }

                if (isPlayerAboveHelipad)
                {
                    UI.landButton.SpecialCase();
                }
                if (player.Health > 0 && !player.changeAltitude)
                {
                    player.Update(gameTime);

                    if (level.IsEveryoneDead() && !completed)
                    {
                        UI.EnableTextOnScreen(0);
                    }
                }
                else
                {
                    if (player.Health <= 0)
                    {
                        player.Alive = false;
                        player.KillPlayer(gameTime);
                    }
                    else if (player.changeAltitude)
                    {
                        if (player.landing)
                        {
                            player.LandPlayer(gameTime);
                        }
                        else if (player.lifting)
                        {
                            player.LiftPlayer(gameTime);
                        }
                        else
                        {
                            if (PlayerAboveHelipad())
                            {
                                if (level.IsEveryoneDead())
                                {
                                    completed = true;
                                }
                                //On helipad
                                int cost = player.UpdateOnHelipad(gameTime);
                                UI.upgradeButton.Visible(true);
                                UI.upgradeButton.SpecialCase();
                                if (UI.upgradeButton.IsItPressed() || key.IsKeyDown(Keys.U))
                                {
                                    GameData.inGameState = InGameState.Paused;
                                    GameData.pauseReason = PauseReason.Upgrade;
                                }
                            }
                            else
                            {
                                player.UpdateOnLand(gameTime);
                            }
                        }
                    }
                }
                // We collect all the bullets so if the tower get destroyed we can change the tower class to a simple sprite
                if (player.Alive)
                {
                    level.Update(gameTime, player.PlayerSprite);
                }
                UpdateEnemyBullets(gameTime);
                UpdateEnemyExplosionBullets(gameTime);
                UpdateFriendlyBullets(gameTime);
                UpdateFriendlyExplosiveBullets(gameTime);
                UpdateEffects(gameTime);
            }
            else
            {
                if (GameData.pauseReason == PauseReason.Upgrade)
                {
                    UpgradeSystem.Update(gameTime, player);
                    if (UpgradeSystem.finishedButton.IsItReleased())
                    {
                        GameData.inGameState = InGameState.Going;
                    }
                }
            }
            if (UI.enableDeveloperStats)
            {
                UI.UpdateDeveloperStats(CollectDeveloperStats(gameTime));
            }
        }