//creates a scene from an image (using System.Drawing) public static void MakeSceneFromImage(PhysicsObject wallTemplate, PhysicsObject baleTemplate, Player player, PhysicsObject chickenTemplate, string map, Scene s, Vector2[,] collisionMap = null) { //uses a manual collision map if it is given if (collisionMap != null) { for (int i = 0; i < collisionMap.GetLength(0); i++) { new PhysicsObject(TextureName.None, collisionMap[i, 0] * 271 + new Vector2(-135.5f, -94f), 1, new Collider(Vector2.zero, collisionMap[i, 1].x * 271, collisionMap[i, 1].y * 271), restitution: 1, parent: s, isDynamic: false, isDrawn: false); } } int chickenTotal = 0; Bitmap image = new Bitmap(map); float sizeX = wallTemplate.GetSprite().GetWidth() / wallTemplate.LocalScale.x; float sizeY = wallTemplate.GetSprite().GetWidth() / wallTemplate.LocalScale.x; GameObject cache; for (int y = 0; y < image.Height; y++) { for (int x = 0; x < image.Width; x++) { Color c = image.GetPixel(x, y); if (c == wallColor) { cache = wallTemplate.Clone(); cache.LocalPosition = new Vector2(sizeX * x, sizeY * y); s.AddChild(cache); } else if (c == chickenColor) { cache = chickenTemplate.Clone(); cache.LocalPosition = new Vector2(sizeX * x, sizeY * y); s.AddChild(cache); chickenTotal++; } else if (c == playerColor) { player.LocalPosition = new Vector2(sizeX * x, sizeY * y); s.AddChild(player); } else if (c == baleColor) { cache = baleTemplate.Clone(); cache.LocalPosition = new Vector2(sizeX * x, sizeY * y); s.AddChild(cache); } else if (c == sideWallColor) { cache = wallTemplate.Clone(); cache.LocalPosition = new Vector2(sizeX * x, sizeY * y); cache.SetSprite(new Sprite(Game.GetTextureFromName(TextureName.SideWall), cache, RLColor.WHITE)); cache.GetSprite().SetLayer(SpriteLayer.Foreground); s.AddChild(cache); } } } //deletes the templates just incase they are being used in any way that they shouldn't be baleTemplate.RemoveCollider(s); baleTemplate.Delete(); chickenTemplate.RemoveCollider(s); chickenTemplate.Delete(); wallTemplate.RemoveCollider(s); wallTemplate.Delete(); //tells the player how many chickens there are in a map (as the player controls the hunger bar) player.chickenTotalInScene = chickenTotal; }