public LoadTile ( int x, int y, |
||
x | int | |
y | int | |
chunk | ||
Résultat |
public TerrainTile LoadTile(int x, int y, TerrainChunk chunk = null)
{
TerrainTile tile = null;
tile = new TerrainTile(chunk);
tile.X = x;
tile.Y = y;
tile.Height = (float)Math.Round(m_terrain.GetHeight(x, y));
tile.m_value = (float)m_terrain.GetValue(x, y);
tile.Bounds = new RectangleF(x, y, 1, 1);
tile.Terrain = GetTerrainType(x, y);
tile.m_temp = Math.Abs(Math.Round(m_tempurature.GetHeight(x, y), 0));
tile.m_tempVal = m_tempurature.GetValue(x, y);
return tile;
}
/// <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; }