public void PlaceTower(Tower t, Vector2 m, float width) { PlaceTower(t, (int)(m.X / GridSize.X), (int)(m.Y / GridSize.Y), (int)(width / GridSize.X), (int)(width / GridSize.Y)); }
public void PlaceTower(Tower t, int x, int y, int width, int height) { int lx = (int)(x - width / 2); int ly = (int)(y - width / 2); int hx = lx + width; int hy = ly + height; // Attempt to place the tower, if possible // TODO: Handle this better? try { // Don't do anything if there is a tower or a road in the way. for (int i = lx + 1; i < hx - 1; i++) { for (int j = ly + 1; j < hy - 1; j++) { if (Grid[i, j].isRoad) { return; } if (Grid[i, j].theTower != null) return; } } } // If part of the tower goes out of range, just return catch (IndexOutOfRangeException) { return; } // Put it in the collection Towers.Add(t); t.Position = new Vector2(x * GridSize.X, y * GridSize.Y); // Don't do anything if there is a tower or a road in the way. //TODO: Does this actually work? // If not, should it be removed from the collection..? for (int i = lx; i < hx; i++) { for (int j = ly; j < hy; j++) { Grid[i, j].theTower = t; } } }
public GridPosition(Tower t, bool ir) { theTower = t; isRoad = ir; }