public void Extend(int left, int right, int up, int down) { Position -= new Vector2(left * CellWidth, up * CellHeight); int newWidth = Data.Columns + left + right; int newHeight = Data.Rows + up + down; if (newWidth <= 0 || newHeight <= 0) { Data = new VirtualMap <bool>(0, 0); return; } var newData = new VirtualMap <bool>(newWidth, newHeight); //Center for (int x = 0; x < Data.Columns; x++) { for (int y = 0; y < Data.Rows; y++) { int atX = x + left; int atY = y + up; if (atX >= 0 && atX < newWidth && atY >= 0 && atY < newHeight) { newData[atX, atY] = Data[x, y]; } } } //Left for (int x = 0; x < left; x++) { for (int y = 0; y < newHeight; y++) { newData[x, y] = Data[0, Calc.Clamp(y - up, 0, Data.Rows - 1)]; } } //Right for (int x = newWidth - right; x < newWidth; x++) { for (int y = 0; y < newHeight; y++) { newData[x, y] = Data[Data.Columns - 1, Calc.Clamp(y - up, 0, Data.Rows - 1)]; } } //Top for (int y = 0; y < up; y++) { for (int x = 0; x < newWidth; x++) { newData[x, y] = Data[Calc.Clamp(x - left, 0, Data.Columns - 1), 0]; } } //Bottom for (int y = newHeight - down; y < newHeight; y++) { for (int x = 0; x < newWidth; x++) { newData[x, y] = Data[Calc.Clamp(x - left, 0, Data.Columns - 1), Data.Rows - 1]; } } Data = newData; }
public void Extend(int left, int right, int up, int down) { Position -= new Vector2(left * TileWidth, up * TileHeight); int newWidth = TilesX + left + right; int newHeight = TilesY + up + down; if (newWidth <= 0 || newHeight <= 0) { Tiles = new VirtualMap <MTexture>(0, 0); return; } var newTiles = new VirtualMap <MTexture>(newWidth, newHeight); //Center for (int x = 0; x < TilesX; x++) { for (int y = 0; y < TilesY; y++) { int atX = x + left; int atY = y + up; if (atX >= 0 && atX < newWidth && atY >= 0 && atY < newHeight) { newTiles[atX, atY] = Tiles[x, y]; } } } //Left for (int x = 0; x < left; x++) { for (int y = 0; y < newHeight; y++) { newTiles[x, y] = Tiles[0, Calc.Clamp(y - up, 0, TilesY - 1)]; } } //Right for (int x = newWidth - right; x < newWidth; x++) { for (int y = 0; y < newHeight; y++) { newTiles[x, y] = Tiles[TilesX - 1, Calc.Clamp(y - up, 0, TilesY - 1)]; } } //Top for (int y = 0; y < up; y++) { for (int x = 0; x < newWidth; x++) { newTiles[x, y] = Tiles[Calc.Clamp(x - left, 0, TilesX - 1), 0]; } } //Bottom for (int y = newHeight - down; y < newHeight; y++) { for (int x = 0; x < newWidth; x++) { newTiles[x, y] = Tiles[Calc.Clamp(x - left, 0, TilesX - 1), TilesY - 1]; } } Tiles = newTiles; }