/// <summary> /// Creates a nee tile map /// </summary> /// <param name="chunksize">The lenght of each side of a chunk. Must be greater than two.</param> public TileMap(int chunksize) { if (chunksize <= 2) { throw new ArgumentException("Chunksize must be greater than 2.", nameof(chunksize)); } _map = new TileChunk <T>(chunksize); _size = new ChunckSize(chunksize); }
public T this[int x, int y] { get { (int xMajor, int xminor) = TranslateCoordinate(x); (int yMajor, int yminor) = TranslateCoordinate(y); IRecursiveTileMap <T> submap = _submap[xMajor, yMajor]; return(submap == null ? default : submap[xminor, yminor]); } set { (int xMajor, int xminor) = TranslateCoordinate(x); (int yMajor, int yminor) = TranslateCoordinate(y); IRecursiveTileMap <T> submap = _submap[xMajor, yMajor] ?? (_submap[xMajor, yMajor] = GenerateSubmap()); submap[xminor, yminor] = value; } }
public RecursiveTileMap(IRecursiveTileMap <T> center, int submapSize) : this((byte)((center as RecursiveTileMap <T>)?.Level + 1 ?? 1), submapSize) { _submap[_submapSize / 2, _submapSize / 2] = center; }