public void Initialize(ConfigOption option) { levelConfig = ConfigFile.FromFile(option.Value); { var physicsSection = levelConfig["Physics"]; PhysicsScale = physicsSection["scale"]; GroundFriction = physicsSection["groundFriction"]; World = new World(physicsSection["gravity"].AsVector2(), physicsSection["doSleep"].AsBool()); World.ContinuousPhysics = physicsSection["continuousPhysics"].AsBool(); World.ContactListener = this; World.DebugDraw = game.PhysicsDebugDrawer; } LevelGenerator = new LevelGenerator(this); bodyList = LevelGenerator.generateLevel(); var viewport = game.GraphicsDevice.Viewport; InitializePlayers(); camera = new Camera2D(game); camera.Initialize(); camera.Focus = new PhantomObject(game); camera.Position = levelConfig["Camera"]["startPos"].AsVector2(); camera.ViewBounds = levelConfig["Camera"]["viewBounds"].AsRectangle(); camera.MaxMoveSpeed = levelConfig["Camera"]["maxMoveSpeed"]; playerBounds = CreatePhysicalViewBounds(); var gameObjectsConfig = ConfigFile.FromFile(levelConfig.GlobalSection["objects"]); foreach (var section in gameObjectsConfig.Sections) { if (section.Value == gameObjectsConfig.GlobalSection) { // Skip the global section because it can not contain any useful info in this case. continue; } var go = GameObject.Create(game, section.Key, section.Value); GameObjects.Add(go); } Menu.InitializeFromConfigFile(levelConfig.GlobalSection["userInterface"].AsConfigFile()); levelConfig.IfSectionExists("Audio", section => { section.IfOptionExists("ambientCue", opt => AmbientMusicCue = opt); }); if (!levelConfig.Sections.ContainsKey("Debug")) { return; } var debugSection = levelConfig["Debug"]; debugSection.IfOptionExists("drawPhysics", opt => game.drawPhysics = opt.AsBool()); debugSection.IfOptionExists("drawVisualHelpers", opt => { if (opt.AsBool()) game.drawVisualHelpers.SetNormal(); else game.drawVisualHelpers.SetNone(); }); debugSection.IfOptionExists("drawDebugData", opt => { if (opt.AsBool()) game.drawDebugData.SetNormal(); else game.drawDebugData.SetNone(); }); }