public void LoadContent(ContentManager content) { spriteBatchEffect = new BasicEffect(graphics); spriteBatchEffect.TextureEnabled = true; liveContent.ReadMetadata("Content.yaml"); Texture2D shipTexture = liveContent.GetTexture("Hulls/ship.png"); Texture2D squareTexture = liveContent.GetTexture("square.png"); Texture2D asteroid1Texture = liveContent.GetTexture("Sprites/Asteroids/asteroid1.png"); Texture2D asteroid2Texture = liveContent.GetTexture("Sprites/Asteroids/asteroid2.png"); Texture2D asteroid3Texture = liveContent.GetTexture("Sprites/Asteroids/asteroid3.png"); Texture2D asteroid4Texture = liveContent.GetTexture("Sprites/Asteroids/asteroid4.png"); Texture2D[] asteroidTextures = { asteroid1Texture, asteroid2Texture, asteroid3Texture, asteroid4Texture }; // Body templates bodyTemplates = PhysicsShapeLoader.LoadBodies(File.ReadAllText("./content/Bodies.xml")); // Scene setup var enemyShipRef = CreateShip(shipTexture, bodyTemplates["ship"], new Vector2(-5, 0), shipTexture, bodyTemplates["square"], 40); shipRef = CreateShip(shipTexture, bodyTemplates["ship"], new Vector2(0, 0), shipTexture, bodyTemplates["square"], 20); PhysicsObjectTemplate[] asteroidTemplates = new PhysicsObjectTemplate[4]; for (int j = 0; j < 4; j++) { asteroidTemplates[j] = new PhysicsObjectTemplate { BodyTemplate = bodyTemplates[$"asteroid{j+1}"], Texture = asteroidTextures[j] }; } for (int i = 0; i < 200; i++) { var type = (int)(Mathf.Bias(Mathf.Random(0, 1), 0.3f) * 4); var template = asteroidTemplates[type]; float radius = 100; do { template.Position = new Vector2(Mathf.Random(-radius, radius), Mathf.Random(-radius, radius)); } while (template.Position.LengthSquared() < 100); var po = template.Create(this).Item2; po.Body.Rotation = Mathf.Random(0, Mathf.TAU); po.Body.AngularVelocity = Mathf.Random(-1, 1) / po.Body.Mass; po.Body.LinearVelocity = Mathf.Random(0, 0.1f) * Mathf.RandomUnit() / po.Body.Mass; } polygonEffect = new BasicEffect(graphics); polygonEffect.VertexColorEnabled = true; }