public Game(Assets assets, Level level) { player = new Player(assets); player.Box.Position = level.Start; this.level = level; infoText = new Text("Foo", assets.Font("Ubuntu-R.ttf"), 20); infoText.Color = Color.Black; }
public Level DecodeLevel(Assets assets) { Image img = assets.Image(path); int width = (int)img.Size.X, height = (int)img.Size.Y; L.I($"Loading level \"{name}\" with {width}x{height}={width * height} tiles"); Dictionary<uint, BlockType> map = mapping .Select(t => new KeyValuePair<uint, BlockType>( uint.Parse(t.Key, System.Globalization.NumberStyles.HexNumber), t.Value.LoadBlockType(assets))) .ToDictionary(t => t.Key, t => t.Value); var blocks = new List<Block>(width * height); var bg = assets.Sprite(background); Level l = new Level(width, height, bg, gravity, start); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Color pixel = img.GetPixel((uint)x, (uint)y); UInt32 argb = (((UInt32)pixel.A) << 24) + (((UInt32)pixel.R) << 16) + (((UInt32)pixel.G) << 8) + ((UInt32)pixel.B); BlockType blockType; map.TryGetValue(argb, out blockType); l[x, y] = new Block(blockType); } } return l; }