Hi, I'm developing a Tower Defense game and I'm close to finish it. I put a lot of effort on it but I'm not even a programmer haha. The problem is I need to add one last system to the game and Is the capability to sell the Towers I place on the game.
When you place a tower on the game, the Tower are stored in an Array called "towers" and the Tile where you place it in another array called "nonPlacableTiles" (because you can't put another tower on it). And there are different towers in the game and all of the towers are stored in the same array.
I make a Sell Button who uses the same logic of a Tower, when you click it you can place it in the correct place, the Tower slot (It's a tile with a circle to put the Tower on). And I manage to remove the Tile from the array "nonPlacableTiles" using this.
nonPlacableTiles.splice(nonPlacableTiles.indexOf(currTile), 1);
And now I can put towers above it because it "clears" the Tile when I place the "Sell Tower" above one Tower.
But the question is: ¿How can I remove the tower?. And how can the code do to identify the tower when I place the "Sell Tower" in the Tile. I have the variable "currTower" who stores the last tower you place in the game. But If I delete it like I say it only remove the LAST tower placed. And I have "towers" the Array to store the towers.
Sorry if I could not explain it well enough but I'm from Argentina and I'm doing my best. If you can help me I'll be very greatful.