Ejemplo n.º 1
0
        public void Update(GameTime gameTime, GameMode currentLevel, Camera camera)
        {
            ParticleSystem.Update();

            if (Session.IsActive)
            {
                if (Session.IsHost)
                {

                }
                else
                {
                    Session.EntityPacket?.ExtractTo(this);
                }
            }

            this.GameTime = gameTime;
            this.Camera = camera;

            if (currentLevel == GameMode.Edit)
            {
                LevelEditor.Update(gameTime, currentLevel);
            }
            else
            {
                SoundtrackManager.PlayTrack(WorldData.SoundtrackId, true);

                Rectangle cameraRect = Player.GetCollRectangle();

                camera.UpdateSmoothly(cameraRect, WorldData.LevelWidth, WorldData.LevelHeight, Player.IsDead);
            }

            TimesUpdated++;

            Background.Update(camera);
            _placeNotification.Update(gameTime);
            WorldData.Update(gameTime);
            LightEngine.Update();
            UpdateInBackground();

            foreach (Cloud c in CloudList)
            {
                c.CheckOutOfRange();
                c.Update(gameTime);
            }

            if (CurrentGameMode == GameMode.Play)
            {
                for (int i = 0; i < Entities.Count; i++)
                {
                    Entity entity = Entities[i];
                    if (entity.IsDead)
                        continue;

                    if (entity is Enemy)
                    {
                        Enemy enemy = (Enemy)entity;
                        enemy.Update();
                    }
                    if (entity is Obstacle)
                    {
                        Obstacle obstacle = (Obstacle)entity;
                        obstacle.Update();
                    }
                    if (entity is Item)
                    {
                        Item power = (Item)entity;
                        power.Update();
                    }
                    if (entity is Projectile)
                    {
                        Projectile proj = (Projectile)entity;
                        proj.Update(Player, gameTime);
                    }
                    if (entity is NonPlayableCharacter)
                    {
                        NonPlayableCharacter npc = (NonPlayableCharacter)entity;
                        npc.Update();
                    }
                    if (entity is Sign)
                    {
                        Sign sign = (Sign)entity;
                        sign.Update();
                    }
                    if (entity is CheckPoint)
                    {
                        CheckPoint ch = (CheckPoint)entity;
                        ch.Update();
                    }
                }
            }

            foreach (Key key in KeyList)
            {
                key.Update(Player);
                if (key.ToDelete)
                {
                    KeyList.Remove(key);
                    break;
                }
            }

            foreach (int tileNumber in VisibleTileArray)
            {
                if (tileNumber >= 0 && tileNumber < TileArray.Length)
                {
                    TileArray[tileNumber]?.Update(gameTime);
                }
            }
        }