//makes a new tile in specified location private Tile NewTile(int i, int j) { Tile t =new Tile(); //location is scroll added to row and column * tile size add the initial grid coordinates t.Loc = new Vector2((-scrollX+j) * Tile.SIZE + gridX, (-scrollY+i) * Tile.SIZE + gridY); return t; }
//adds specified number of columns, a negative num removes cols //invert parameter removes it from smaller-index side public void AddCol(int num, bool invert) { if (width + num <= 0) { return; } //cancel if going below 0 Tile[,] g = new Tile[height, width + num]; if (invert) { scrollX+=num; if (num < 0 && Math.Abs(num) > scrollX) { scrollX -= num; ScrollGrid(+Tile.SIZE * num,0); } } for (int i = 0; i < height; i++) { //fill new grid for (int j = 0; j < width + num; j++) { if (j < width && !invert) { g[i, j] = grid[i, j]; } else if(j>=num && invert){ g[i, j] = grid[i, j - num]; }else { g[i, j] = NewTile(i, j); } } } //replace grid with new grid grid = g; width += num; }
//adds specified number of rows, a negative num removes rows //invert parameter removes it from smaller-index side public void AddRow(int num,bool invert) { if (height + num <= 0) { return; } //cancel if going below 0 Tile[,] g = new Tile[height+num, width]; if (invert) { scrollY+=num; if (num < 0 && Math.Abs(num) > scrollY) { scrollY -= num; ScrollGrid(0, +Tile.SIZE * num); } } for (int i = 0; i < height+num; i++) { //fill new grid for (int j = 0; j < width; j++) { if (i < height && !invert) { g[i, j] = grid[i, j]; } else if (i >= num && invert) { g[i, j] = grid[i-num, j]; } else { g[i, j] = NewTile(i,j); } } } //replace grid with new grid grid = g; height += num; }