Example #1
0
        public static void TrimMap(Map map, int width, int height)
        {
            map.Width = width;
            map.Height = height;

            var newCollisionLayer = new MapCollisionLayer(width, height);

            for (int y = 0; y < newCollisionLayer.Height; y++)
            {
                for (int x = 0; x < newCollisionLayer.Width; x++)
                {
                    var tile = new Vector2(x, y);

                    CollisionValues value = map.CollisionLayer.Width > tile.X && map.CollisionLayer.Height > tile.Y
                        ? map.CollisionLayer.GetCollisionValue(tile)
                        : CollisionValues.Passable;

                    newCollisionLayer.SetCollisionValue(tile, value);
                }
            }

            map.CollisionLayer = newCollisionLayer;

            for (int i = 0; i < map.Layers.Count; i++)
            {
                var newLayer = new MapLayer(width, height);

                newLayer.Id = map.Layers[i].Id;

                for (int y = 0; y < newLayer.Height; y++)
                    for (int x = 0; x < newLayer.Width; x++)
                    {
                        var tile = new Vector2(x, y);
                        if (map.Layers[i].Width > x && map.Layers[i].Height > y)
                        {
                            newLayer.SetTexture(tile, map.Layers[i].Map[y, x]);
                        }
                    }

                map.Layers[i] = newLayer;
            }
        }