public void Initialize(ConfigOption option) { levelConfig = ConfigFile.FromFile(option.Value); { var physicsSection = levelConfig["Physics"]; PhysicsScale = physicsSection["scale"]; GroundFriction = physicsSection["groundFriction"]; World = new scPhysicsWorld(); World.game = game; physicsSection.IfOptionExists("gravity", o => World.gravity = o.AsVector2()); // physicsSection["gravity"].AsVector2(), physicsSection["doSleep"].AsBool() // World.ContinuousPhysics = physicsSection["continuousPhysics"].AsBool(); physicsWorldDebugRenderer = new scPhysicsWorldDebugRenderer(); physicsWorldDebugRenderer.world = World; } LevelGenerator = new LevelGenerator(this); // bodyList = LevelGenerator.generateLevel(); var viewport = game.GraphicsDevice.Viewport; InitializePlayers(); camera = new Camera2D(game); camera.Initialize(); camera.Position = levelConfig["Camera"]["startPos"].AsVector2(); camera.ViewBounds = levelConfig["Camera"]["viewBounds"].AsRectangle(); camera.MaxMoveSpeed = levelConfig["Camera"]["maxMoveSpeed"]; 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(); }); { var circleshape = new scCircleShape(); circleshape.radius = 75; var bodyPartDescription = new scBodyPartDescription(); bodyPartDescription.shape = circleshape; var bodyDescription = new scBodyDescription(); bodyDescription.bodyType = scBodyType.Static; bodyDescription.transform.position = new Vector2(-150, 0); var bodyPartDescriptions = new List<scBodyPartDescription>(); bodyPartDescriptions.Add(bodyPartDescription); var body = World.createBody(bodyDescription, bodyPartDescriptions); } { var rectangleshape = scRectangleShape.fromLocalPositionAndHalfExtents(new Vector2(0, 0), new Vector2(75, 30)); var bodyPartDescription = new scBodyPartDescription(); bodyPartDescription.shape = rectangleshape; var bodyDescription = new scBodyDescription(); bodyDescription.bodyType = scBodyType.Static; bodyDescription.transform.position = new Vector2(50, 150); var bodyPartDescriptions = new List<scBodyPartDescription>(); bodyPartDescriptions.Add(bodyPartDescription); var body = World.createBody(bodyDescription, bodyPartDescriptions); } { var edgeshape = new scEdgeShape(); edgeshape.start = new Vector2(-20, -40); edgeshape.end = new Vector2(20, 40); var bodyPartDescription = new scBodyPartDescription(); bodyPartDescription.shape = edgeshape; var bodyDescription = new scBodyDescription(); bodyDescription.bodyType = scBodyType.Static; bodyDescription.transform.position = new Vector2(100, 50); var bodyPartDescriptions = new List<scBodyPartDescription>(); bodyPartDescriptions.Add(bodyPartDescription); var body = World.createBody(bodyDescription, bodyPartDescriptions); TESTEDGE = body; } { var rectangleshape = scRectangleShape.fromLocalPositionAndHalfExtents(new Vector2(0, 0), new Vector2(40, 40)); var bodyPartDescription = new scBodyPartDescription(); bodyPartDescription.shape = rectangleshape; var bodyDescription = new scBodyDescription(); bodyDescription.bodyType = scBodyType.Static; bodyDescription.transform.position = new Vector2(200, 50); var bodyPartDescriptions = new List<scBodyPartDescription>(); bodyPartDescriptions.Add(bodyPartDescription); var body = World.createBody(bodyDescription, bodyPartDescriptions); TESTRECTANGLE = body; } }
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(); }); }