コード例 #1
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "GridWorld" /> class.
        /// </summary>
        /// <param name = "boundingBox">
        ///   The bounding box defines the world's size.
        /// </param>
        /// <param name = "tileDimensions">
        ///   The tile dimensions.
        /// </param>
        /// <param name = "itemCache">
        ///   The cache for all <see cref = "Item">Items</see> in this world.
        /// </param>
        public GridWorld(BoundingBox boundingBox, Vector tileDimensions, ItemCache itemCache)
        {
            // 2D grid: extend Z to max possible
            this.rectangleArea = new BoundingBox
                {
                    Min = new Vector { X = boundingBox.Min.X, Y = boundingBox.Min.Y, Z = int.MinValue },
                    Max = new Vector { X = boundingBox.Max.X, Y = boundingBox.Max.Y, Z = int.MaxValue }
                };

            var size = new Vector { X = boundingBox.Max.X - boundingBox.Min.X + 1, Y = boundingBox.Max.Y - boundingBox.Min.Y + 1 };
            if (tileDimensions.X <= 0)
            {
                tileDimensions.X = size.X;
            }

            if (tileDimensions.Y <= 0)
            {
                tileDimensions.Y = size.Y;
            }

            this.tileDimensions = tileDimensions;
            this.tileSize = new Vector { X = tileDimensions.X - 1, Y = tileDimensions.Y - 1 };
            this.itemCache = itemCache;

            var regionsX = (int)Math.Ceiling(size.X / (double)tileDimensions.X);
            var regionsY = (int)Math.Ceiling(size.Y / (double)tileDimensions.Y);

            this.worldRegions = new Region[regionsX][];
            Vector current = boundingBox.Min;
            for (int x = 0; x < regionsX; x++)
            {
                this.worldRegions[x] = new Region[regionsY];
                for (int y = 0; y < regionsY; y++)
                {
                    this.worldRegions[x][y] = new Region(current);
                    current.Y += tileDimensions.Y;
                }

                current.X += tileDimensions.X;
                current.Y = boundingBox.Min.Y;
            }
        }
コード例 #2
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "GridWorld" /> class.
 /// </summary>
 /// <param name = "corner1">
 ///   One corner of the world.
 /// </param>
 /// <param name = "corner2">
 ///   The other corner of the world.
 /// </param>
 /// <param name = "tileDimensions">
 ///   The tile dimensions.
 /// </param>
 /// <param name = "itemCache">
 ///   The cache for all <see cref = "Item">Items</see> in this world.
 /// </param>
 public GridWorld(Vector corner1, Vector corner2, Vector tileDimensions, ItemCache itemCache)
     : this(BoundingBox.CreateFromPoints(corner1, corner2), tileDimensions, itemCache)
 {
 }