コード例 #1
0
        public void Resize(int width, int height)
        {
            var oldMapTiles     = Tiles;
            var oldMapResources = Resources;
            var oldMapHeight    = Height;
            var newSize         = new Size(width, height);

            Tiles     = CellLayer.Resize(oldMapTiles, newSize, oldMapTiles[MPos.Zero]);
            Resources = CellLayer.Resize(oldMapResources, newSize, oldMapResources[MPos.Zero]);
            Height    = CellLayer.Resize(oldMapHeight, newSize, oldMapHeight[MPos.Zero]);
            MapSize   = new int2(newSize);

            var tl = new MPos(0, 0);
            var br = new MPos(MapSize.X - 1, MapSize.Y - 1);

            AllCells = new CellRegion(Grid.Type, tl.ToCPos(this), br.ToCPos(this));
            SetBounds(new PPos(tl.U + 1, tl.V + 1), new PPos(br.U - 1, br.V - 1));
        }
コード例 #2
0
        public void SetBounds(MPos tl, MPos br)
        {
            // The tl and br coordinates are inclusive, but the Rectangle
            // is exclusive.  Pad the right and bottom edges to match.
            Bounds            = Rectangle.FromLTRB(tl.U, tl.V, br.U + 1, br.V + 1);
            CellsInsideBounds = new CellRegion(TileShape, tl.ToCPos(this), br.ToCPos(this));

            // Directly calculate the projected map corners in world units avoiding unnecessary
            // conversions.  This abuses the definition that the width of the cell is always
            // 1024 units, and that the height of two rows is 2048 for classic cells and 1024
            // for diamond cells.
            var wtop    = tl.V * 1024;
            var wbottom = (br.V + 1) * 1024;

            if (TileShape == TileShape.Diamond)
            {
                wtop    /= 2;
                wbottom /= 2;
            }

            ProjectedTopLeft     = new WPos(tl.U * 1024, wtop, 0);
            ProjectedBottomRight = new WPos(br.U * 1024 - 1, wbottom - 1, 0);
        }