LoadTile() public method

public LoadTile ( int x, int y, TerrainChunk chunk = null ) : TerrainTile
x int
y int
chunk TerrainChunk
return TerrainTile
Ejemplo n.º 1
0
        /// <summary>
        /// Loads tiles from world that are contained within chunkBounds
        /// </summary>
        /// <param name="world"></param>
        /// <param name="chunkBounds"></param>
        public TerrainChunk(World world, RectangleF chunkBounds)
            : this()
        {
            //Calculate total tiles
            int totalTiles = (int)chunkBounds.Width * (int)chunkBounds.Height;

            //Loop through each tile
            for (int index = 0; index < totalTiles; index++)
            {
                //Convert index value into x and y coordinates.
                int cellX = (int)(index / chunkBounds.Height) + (int)chunkBounds.X;
                int cellY = (int)(index % chunkBounds.Height) + (int)chunkBounds.Y;

                //Load tile.
                TerrainTile tile = world.LoadTile(cellX, cellY, this);

                m_tileCount[tile.Terrain]++;

                //Insert new tile into chunk QuadTree
                m_tiles.Insert(tile);
            }

            //Assign local variables
            m_world = world;
            m_bounds = chunkBounds;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads tiles from world that are contained within chunkBounds
        /// </summary>
        /// <param name="world"></param>
        /// <param name="chunkBounds"></param>
        public TerrainChunk(World world, int offsetX, int offsetY, int radius)
            : this()
        {
            int x, y;

            for (y = -radius; y <= radius; y++)
                for (x = -radius; x <= radius; x++)
                    if ((x * x) + (y * y) <= (radius * radius))
                    {
                        //chunkBounds = new System.Drawing.RectangleF(x, y, 1, 1);

                        TerrainTile tile = world.LoadTile(x + offsetX, y + offsetY, this);

                       m_tileCount[tile.Terrain]++;

                       //Insert new tile into chunk QuadTree
                       m_tiles.Insert(tile);
                    }

            //Assign local variables
            m_world = world;
            m_bounds = new RectangleF(offsetX, offsetY, radius * 2, radius * 2);
        }