Example #1
0
File: Game.cs Project: tilpner/hp
 public BlockType LoadBlockType(Assets assets) {
     var sp = assets.Sprite(Sprite);
     sp.Scale = new Vector2f(1F / sp.Texture.Size.X, 1F / sp.Texture.Size.Y);
     return new BlockType(Name, sp, Collider, Friction);
 }
Example #2
0
File: Game.cs Project: tilpner/hp
        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;
        }